源码看JAVA【十】Short
生活随笔
收集整理的這篇文章主要介紹了
源码看JAVA【十】Short
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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功能類似
總結
以上是生活随笔為你收集整理的源码看JAVA【十】Short的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Goolgle推荐 onActivi
- 下一篇: java instant_Java In