numbers - Why does java.lang.Long's .longValue() cast its (long) instance value to long? -
i have been investigating java.lang.long class source code.
consider this:
public final class long extends number implements comparable<long> { .... private final long value; .... public long longvalue() { return (long)value; } .... } what reason cast long long?
why not reralize serialize (?) number class in case?
p.s.1 source code link
i have these possible explanations:
- carelessness of developers
- compliance unified code style
- it made special case, don't understand why.
p.s.2
my java version - 1.7.0_45-b18
p.s.3 information:
integer:
public final class integer extends number implements comparable<integer> { .... private final int value; .... public int intvalue() { return value; } .... } short:
public final class short extends number implements comparable<short> { .... private final short value; .... public short shortvalue() { return value; } .... } and same byte , character. (none of these cast like-to-like.)
is problem, or may forgotten?
i have assumption made code unified related methods?
observe single code style.
public short shortvalue() { return (short)value; } public int intvalue() { return (int)value; } public long longvalue() { return (long)value; } public float floatvalue() { return (float)value; } public double doublevalue() { return (double)value; } but noticed in java 1.6(1.6_0_45 @ least) integer class
public int intvalue() { return (int)value; } but in java 1.7 integer class
public int intvalue() { return value; } conclusion: developers have not paid attention aspect.
p.s. assumption only.
Comments
Post a Comment