1、最大值与最小值
/**
* A constant holding the minimum value a {@code short} can
* have, -2<sup>15</sup>.
*/
public static final short MIN_VALUE = -32768;
/**
* A constant holding the maximum value a {@code short} can
* have, 2<sup>15</sup>-1.
*/
public static final short MAX_VALUE = 32767;
2、ShortCache
定义缓存-128~127
private static class ShortCache {
private ShortCache(){}
static final Short cache[] = new Short[-(-128) + 127 + 1];
static {
for(int i = 0; i < cache.length; i++)
cache[i] = new Short((short)(i - 128));
}
}
3、hashCode与equals
返回相应的short值
/**
* Returns a hash code for a {@code short} value; compatible with
* {@code Short.hashCode()}.
*
* @param value the value to hash
* @return a hash code value for a {@code short} value.
* @since 1.8
*/
public static int hashCode(short value) {
return (int)value;
}
/**
* Compares this object to the specified object. The result is
* {@code true} if and only if the argument is not
* {@code null} and is a {@code Short} object that
* contains the same {@code short} value as this object.
*
* @param obj the object to compare with
* @return {@code true} if the objects are the same;
* {@code false} otherwise.
*/
public boolean equals(Object obj) {
if (obj instanceof Short) {
return value == ((Short)obj).shortValue();
}
return false;
}
4、其余与Integer功能类似