Since primitive types are not objects with all effects, also if java added some workarounds (for example, implicit unpacking of these types).
You can choose it in different ways, for example:
Long l3 = ((Double)Math.pow(5, 2)).longValue();
This works because Java can:
- for implicit transfer from a primitive type to another when you refer to them only with a regular type declaration, for example:
int to long - for implicit casting from a box type to another, for example.
int to long - to switch between boxed and unboxed types when they are the same type, e.g.
long to long
source share