Java – boxed values are unboxed and then repacked immediately
•
Java
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
二维码