I came across this piece of legacy code (Java 6) (that's simplified version that pinpoints my issue):
Object o;
o = new Long (3L);
Double d;
d = (Double) o;
This one above is obviously not working as wrappers can be cast only to corresponding primitive types. I fixed this by:
Long toConvert = (Long) o;
String convert = toConvert.toString();
d= Double.parseDouble(convert);
and it works fine, except being ugly. I tried another solution:
d = (double) o;
and I worked as well, but when I checked this solution (pure curiosity) in new Java 8 project I got
java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Double
Does Java 6 differs from Java 8 when it comes to primitive wrappers in a way that can explain observed behaviour?