One glance at the source for them says why:
public byte byteValue() { return (byte)intValue(); } public short shortValue() { return (short)intValue(); }
Both of them rely on intValue() be defined and just use what they provide for this.
It makes me wonder why they donβt just do
public int intValue() { return (int)longValue(); }
Because the same rule applies.
Note that nothing says that you cannot override these methods anyway. They should not be abstract so that you can redefine them.
Results on my machine:
C:\Documents and Settings\glow\My Documents>java SizeTest int: 45069467 short: 45069467 byte: 90443706 long: 11303499 C:\Documents and Settings\glow\My Documents>
Grade:
class SizeTest { public static void main(String[] args) { int len = 10000; final double inc = 1.01; try { while(true) { len = (int)(len * inc); int[] arr = new int[len]; } } catch(Throwable t) { System.out.println("int: " + len); } len = 10000; try { while(true) { len = (int)(len * inc); short[] arr = new short[len]; } } catch(Throwable t) { System.out.println("short: " + len); } len = 10000; try { while(true) { len = (int)(len * inc); byte[] arr = new byte[len]; } } catch(Throwable t) { System.out.println("byte: " + len); } len = 10000; try { while(true) { len = (int)(len * inc); long[] arr = new long[len]; } } catch(Throwable t) { System.out.println("long: " + len); } } }
corsiKa
source share