Java

Java

Made by DeepSource

Primitive value is boxed, then unboxed to perform primitive coercion JAVA-W1081

Anti-pattern
Major

A boxed value is constructed and then immediately converted into a different primitive type.

Consider performing a direct cast instead.

Bad Practice

Wrapping a primitive and then unwrapping it immediately after is a redundant operation that unnecessarily creates a new object.

int value = new Double(d).intValue();

Recommended

It is better to just cast the primitive to the desired type directly instead.

int value = (int) d;

References