为什么java.lang.Long的.longValue()将其(长)实例值强制转换为long?

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)

什么是投理由longlong

为什么不在这种情况下将序列化(?)重新归类为Number类?

PS1 源代码链接

我有这些可能的解释:

  1. 开发人员粗心大意
  2. 符合一些统一的代码风格
  3. 它是为一些特殊情况而制作的,但我不明白为什么.

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)

同样的ByteCharacter.(这些都不像是喜欢的.)

这是一个问题,还是只是被遗忘?

gst*_*low 4

我假设相关方法的代码是统一的?

遵守单一的代码风格。

 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 这只是我的假设。