本文介绍了如何将double转换为对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写我的程序的一部分,它从txt文件中读取数据。

I am writing part of my program which read data from a txt file.

当我想通过setValue(object)设置JSpinner的值时,我遇到了问题。

I have problem when I want to set value of JSpinner by setValue(object).

我的数据是双倍所以我需要将它转换为对象,但是如何?

My data is double so I need to convert it to object, but how?

LoadData open = new LoadData();
data.setFz(open.giveAwayData());
spinner_1.setValue(data.getFz()); // Fz is double


推荐答案

使用 Double.valueOf(data.getFz())。可以在;基本上,原语具有更好的性能,但是当您需要对象时,盒装类就可用了。一个常见的例子是,它不能是原语。

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.

但是 double 可以传递给需要 Double 或其中一个超类。这是因为。是的,我非常喜欢链接。

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.

这篇关于如何将double转换为对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 02:11