Java: many ways of casting a (long) Object to double
问题 I have an Object obj that I know is actually a long . In some Math code I need it as double . Is it safe to directly cast it to double? double x = (double)obj; Or should I rather cast it first to long and then to double. double x = (double)(long)obj; I also found another (less readable) alternative: double x = new Long((long)obj).doubleValue(); What are the dangers/implications of doing either? Solution Summary : obj is a Number and not a long . Java 6 requires explicit casting, e.g.: double