本文介绍了Java类Long-方法longValue()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Java类Long有一个方法longValue()?那有什么用? Java文档说

Why has the java class Long a method longValue()? And what is the use of that? The java doc says

the numeric value represented by this object after conversion to type long.

是否有我需要的情况?下面的第一个代码代码与第二个代码在任何长值方面都可以不同吗?

Is there a case where I need this? Could the following first code code differ from the second for any long value?

//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();

推荐答案

在Java5之前,没有 Autoboxing and Unboxing ,以便longValue()方法强制转换为原始long并返回.

Before Java5 there is No Autoboxing and Unboxing so that longValue() method casts to primitive long and returns.

public long More ...longValue() {
722         return (long)value;
723     }

因此没有具体区别.在java5之后,下面的代码就足够了

So there is no specific difference. Any way after java5 the below code is enough

Long l = new Long("...");
long myLong = l;

这篇关于Java类Long-方法longValue()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 22:25