I have read source code of java.lang.Number
and I wondered why
intValue()
longValue()
floatValue()
doubleValue()
are abstract but
shortValue()
byteValue()
a concrete.
source code:
public abstract class Number implements java.io.Serializable {
public abstract int intValue();
public abstract long longValue();
public abstract float floatValue();
public abstract double doubleValue();
public byte byteValue() {
return (byte)intValue();
}
public short shortValue() {
return (short)intValue();
}
private static final long serialVersionUID = -8742448824652078965L;
}
Why java founders have made it so?
I don't see big differencies between these method. Its seem as related.
P.S.
from Long class:
public byte byteValue() {
return (byte)value;
}
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;
}
from Integer class
public byte byteValue() {
return (byte)value;
}
public short shortValue() {
return (short)value;
}
public int intValue() {
return value;
}
public long longValue() {
return (long)value;
}
public float floatValue() {
return (float)value;
}
public double doubleValue() {
return (double)value;
}
Hence we are see a lot of same code. I think copy paste
development is bad but I think that Java founders have reasons for this.