How to convert double to object?

懵懂的女人 提交于 2019-12-05 11:51:56

Try casting it to Double (with capital):

spinner_1.setValue((Double) data.getFz());
bcsb1001

Use Double.valueOf(data.getFz()). An explanation of the differences between primitives and boxed primitives can be found here; basically, primitives have better performance but the boxed classes are there for when you need an Object. A common example is with generics, which cannot be primitives.

However, a double can be passed to something requiring a Double or one of its superclasses. This is because of autoboxing. Yes, I like links a lot.

You can use for example the Double constructor to convert double primitive type to a Double object.

Double dObj = new Double(d);

or you can cast it to Double like this:

spinner_1.setValue((Double)data.getFz());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!