Compare Date object with a TimeStamp in Java

tl;dr Use the modern java.time classes instead of those troublesome legacy date-time classes. myPreparedStatement.setObject( … , Instant.now() // Capture the current moment in UTC. ) Old Date-Time Classes Poorly Designed Put more bluntly, the java.sql.Timestamp/.Date/.Time classes are a hack, a bad hack. Like java.util.Date/.Calendar, they are the result of poor design choices. The java.sql types … Read more

Why are two AtomicIntegers never equal?

This is partly because an AtomicInteger is not a general purpose replacement for an Integer. The java.util.concurrent.atomic package summary states: Atomic classes are not general purpose replacements for java.lang.Integer and related classes. They do not define methods such as hashCode and compareTo. (Because atomic variables are expected to be mutated, they are poor choices for … Read more

Why can’t I “static import” an “equals” method in Java?

The collision is actually with Object.equals(). All classes are inherited from Object and therefore have the Object.equals() method which leads to this collision. You’re importing by name, not by signature. You actually can’t import a static method named equals because of this. Or rather, you can import it, but not use it. I do agree … Read more

Is there a “not equal” in a linq join

You don’t need a join for that: var filteredEmployees = groupA.Except(groupB); Note that this will be a sequence of unique employees – so if there are any duplicates in groupA, they will only appear once in filteredEmployees. Of course, it also assumes you’ve got a reasonable equality comparer1. If you need to go specifically on … Read more

Why are 2 Long variables not equal with == operator in Java?

== compares references, .equals() compares values. These two Longs are objects, therefore object references are compared when using == operator. However, note that in Long id1 = 123L; literal value 123L will be auto-boxed into a Long object using Long.valueOf(String), and internally, this process will use a LongCache which has a [-128,127] range, and 123 … Read more