Java中的双倍与双倍 [英] Double vs double in java
本文介绍了Java中的双倍与双倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
Java:比较不同的 double 和 Double
在我的一个实验室的示例 Java 程序中,我有两种不同的方法,分别采用 Double 和 double 参数.
在向它们传递参数时如何区分它们?
In a sample java program for one of my labs, I have two different methods taking Double and double parameters respectively.
How do I differentiate between them when passing arguments to them?
推荐答案
首先,您需要了解这两种类型之间的区别.double
是原始类型,而 Double
是对象.
First off you need to understand the difference between the two types.
double
is a primitive type whereas Double
is an Object.
下面的代码显示了一个重载方法,我认为它与您的实验室代码相似.
The code below shows an overloaded method, which I assume is similar to your lab code.
void doStuff(Double d){ System.out.println("Object call"); }
void doStuff(double d){ System.out.println("Primitive call"); }
您可以通过多种方式调用这些方法:
There are several ways you can call these methods:
doStuff(100);
doStuff(200d);
doStuff(new Double(100));
这些调用将导致:
"Primitive call"
"Primitive call"
"Object call"
这篇关于Java中的双倍与双倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文