为什么java类Long有一个方法longValue()?那有什么用?java doc说
the numeric value represented by this object after conversion to type long.
Run Code Online (Sandbox Code Playgroud)
我需要这个吗?对于任何长值,以下第一个代码是否与第二个代码不同?
//Is there a value where this myLong value contains other...
Long l = new Long("...");
long myLong = l;
//...than this one?
Long l = new Long("...");
long myLong = l.longValue();
Run Code Online (Sandbox Code Playgroud)
在Java5之前有No,Autoboxing and Unboxing所以longValue() 方法转换为原始long并返回.
public long More ...longValue() {
722 return (long)value;
723 }
Run Code Online (Sandbox Code Playgroud)
所以没有具体的区别.在java5之后的任何方式下面的代码就足够了
Long l = new Long("...");
long myLong = l;
Run Code Online (Sandbox Code Playgroud)