在java中双倍与双倍 [英] Double vs double in java
本文介绍了在java中双倍与双倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
Java:不同的双倍和双倍的比较
在我的一个实验室的一个示例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屋!
查看全文