Should autoboxing be avoided in Java?

前端 未结 5 1553
谎友^
谎友^ 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:41

    Autoboxing should be avoided. It can lead to errors because of overloading and it has some performance impact. Nonetheless it may not be an issue in your application. But be aware of the impact.

    Here my post to that: https://effective-java.com/2010/05/the-advantages-and-traps-of-autoboxing/

提交回复
热议问题