I came across https://code.google.com/p/hamcrest/issues/detail?id=130 to add some sugar syntax for Hamcrest matchers. But the idea was rejected by the Hamcrest developers. Any other smart ideas to make tests better readable by avoiding having to type L behind longs? UPDATE See also below the differences when comparing e.g. int and long using default Java laguage (==), standard junit assert (assertTrue) and
Tag: autoboxing
Java convert Arraylist to float[]
How I can do that? I have an arraylist, with float elements. (Arraylist <Float>) it is not working. cannot cast from Object[] to float[] Answer Loop over it yourself. The nullcheck is mandatory to avoid NullPointerException because a Float (an object) can be null while a float (a primitive) cannot be null at all. In case you’re on Java 8
Weird Integer boxing in Java
I just saw code similar to this: When ran, this block of code will print out: I understand why the first is false: because the two objects are separate objects, so the == compares the references. But I can’t figure out, why is the second statement returning true? Is there some strange autoboxing rule that kicks in when an Integer’s