There are instances where a method expects a primitive type double
and you pass a Double
object as a parameter.
Since the compiler unboxes
This is what Java Notes says on autoboxing:
Prefer primitive types
Use the primitive types where there is no need for objects for two reasons.
- Primitive types may be a lot faster than the corresponding wrapper types, and are never slower.
- The immutability (can't be changed after creation) of the wrapper types may make their use impossible.
- There can be some unexpected behavior involving == (compare references) and .equals() (compare values). See the reference below for examples.