Java – boxed values are unboxed and then repacked immediately

I received the findugs error "boxed value is not boxed, and then repack it immediately"

This is the code:

Employee emp = new Employee()
Long lmt = 123L;

emp.setLimit(Long.valueOf(lmt));

Here, the type of employee restriction field is long Can you tell me what the mistake is?

Solution

The problem is that you have to convert long – > long – > long

So in the background:

> Long. Valueof (LMT) converts long to long > EMP setLimit(< long>); Convert to long again

Starting with Java 5, automatic boxing occurs = > your code should be as follows:

Employee emp = new Employee()
Long lmt = 123L;

emp.setLimit(lmt);

even to the extent that:

Employee emp = new Employee()
long lmt = 123L;

emp.setLimit(lmt);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>