I am getting the Findugs error "A boxed value is unboxed and then immediately reboxed".
This is the Code:
Employee emp = new Employee()
Long lmt = 123L;
emp.setLimit(Long.valueOf(lmt));
In this, Employee limit field is of type Long. Could you please let me know what is the error?
The problem is that you're converting Long -> long -> Long.
So in the background:
Long.valueOf(lmt) converts Long to long
emp.setLimit(<long>); converts long to Long againAs of Java 5 autoboxing happens => your code should look like this:
Employee emp = new Employee()
Long lmt = 123L;
emp.setLimit(lmt);
or even:
Employee emp = new Employee()
long lmt = 123L;
emp.setLimit(lmt);
That happens because Long.valueOf(long) will unbox your lmt from Long to long, just to get a Long again. As you said that limit is a Long, you don't need to use Long.valueOf, just use the var:
emp.setLimit(lmt);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With