[英]Boxing unboxing issue
Getting below bug in findbug: 获得findbug中的错误:
A boxed value is unboxed and then immediately reboxed Below is the statement:
装箱的值被取消装箱,然后立即重新装箱。以下是该语句:
deliveryCost = new Double(cost);
where cost
is float type. cost
为浮动类型。
Kindly suggest. 请提示。
That message is a little odd. 该消息有点奇怪。 I'm not sure exactly why you're getting it.
我不确定您为什么要得到它。 But one thing you should change is this:
但是您应该更改的一件事是:
deliveryCost = Double.valueOf(cost);
See if the message goes away when you do that. 查看执行此操作时消息是否消失。 When you say
new Double(...)
it's like telling java, "please, allocate a brand new object for me, even if you can reuse one and get the same effect". 当您说
new Double(...)
,就像告诉java,“请为我分配一个全新的对象,即使您可以重用一个对象并获得相同的效果”。 It's usually not necessary to do. 通常不需要这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.