gst*_*low 26 java numbers long-integer
我一直在调查java.lang.Long类源代码.
考虑一下:
public final class Long extends Number implements Comparable<Long> {
....
private final long value;
....
public long longValue() {
return (long)value;
}
....
}
Run Code Online (Sandbox Code Playgroud)
什么是投理由long来long?
为什么不在这种情况下将序列化(?)重新归类为Number类?
PS1 源代码链接
我有这些可能的解释:
PS2
我的java版本 - 1.7.0_45-b18
PS3 仅供参考:
Integer:
public final class Integer extends Number implements Comparable<Integer> {
....
private final int value;
....
public int intValue() {
return value;
}
....
}
Run Code Online (Sandbox Code Playgroud)
Short:
public final class Short extends Number implements Comparable<Short> {
....
private final short value;
....
public short shortValue() {
return value;
}
....
}
Run Code Online (Sandbox Code Playgroud)
同样的Byte和Character.(这些都不像是喜欢的.)
这是一个问题,还是只是被遗忘?
我假设相关方法的代码是统一的?
遵守单一的代码风格。
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;
}
Run Code Online (Sandbox Code Playgroud)
但我注意到在java 1.6(至少1.6_0_45)中对于Integer类
public int intValue() {
return (int)value;
}
Run Code Online (Sandbox Code Playgroud)
但在java 1.7中Integer类
public int intValue() {
return value;
}
Run Code Online (Sandbox Code Playgroud)
结论:开发者还没有关注这方面。
PS 这只是我的假设。
| 归档时间: |
|
| 查看次数: |
1316 次 |
| 最近记录: |