Should autoboxing be avoided in Java?

前端 未结 5 1586
谎友^
谎友^ 2021-01-17 12:51

There are instances where a method expects a primitive type double and you pass a Double object as a parameter.

Since the compiler unboxes

5条回答
  •  既然无缘
    2021-01-17 13:48

    The rule of thumb is: always use primitives if possible.

    There are cases where this is not possible, like collections, so use wrappers only then.

提交回复
热议问题