I have been investigating the 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 is the reason to cast long
to long
?
Why not reralize serialize (?) it into Number class in this case?
P.S.1 source code link
I have these possible explanations:
- Carelessness of developers
- Compliance with some unified code style
- It was made for some special case, but I don't understand why.
P.S.2
my java version - 1.7.0_45-b18
P.S.3 just for 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 for Byte
and Character
. (None of these cast like-to-like.)
Is it a problem, or may it just be forgotten?