• Java 源码 Short


    介绍

    The Short class wraps a value of primitive type short in an object.

    示例

    public class Test {
      public static void main(String[] args) {
        Short a = Short.valueOf("12");
        Short b = Short.valueOf("12");
        System.out.println(a==b); // true
      }
    }
    

    源码

    public final class Short extends Number implements Comparable<Short> {
    
      /**
       * -2<sup>15</sup>.
       */
      public static final short   MIN_VALUE = -32768;
    
      /**
       * 2<sup>15</sup>-1.
       */
      public static final short   MAX_VALUE = 32767;
    
      public static String toString(short s) {
        return Integer.toString((int)s, 10);
      }
    
      public static short parseShort(String s, int radix)
        throws NumberFormatException {
        int i = Integer.parseInt(s, radix);
        if (i < MIN_VALUE || i > MAX_VALUE)
          throw new NumberFormatException("Value out of range.");
        return (short)i;
      }
    
      public static Short valueOf(String s, int radix)
        throws NumberFormatException {
        return valueOf(parseShort(s, radix));
      }
    
    
      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));
        }
      }
    
      public static Short valueOf(short s) {
        final int offset = 128;
        int sAsInt = s;
        if (sAsInt >= -128 && sAsInt <= 127) {
          return ShortCache.cache[sAsInt + offset];
        }
        return new Short(s);
      }
    
      private final short value;
    
      public Short(short value) {
        this.value = value;
      }
    
      public Short(String s) throws NumberFormatException {
        this.value = parseShort(s, 10);
      }
    
      public String toString() {
        return Integer.toString((int)value);
      }
    
      public static int hashCode(short value) {
        return (int)value;
      }
    
      public boolean equals(Object obj) {
        if (obj instanceof Short) {
          return value == ((Short)obj).shortValue();
        }
        return false;
      }
    
      public static int compare(short x, short y) {
        return x - y;
      }
    }
    
  • 相关阅读:
    erl_0012 timer:tc 测试模块函数调用运行耗时
    erl_0011 erlang 定时器相关
    erl0010
    erl0009
    erl0008
    erl0007
    erl0006
    erl0005
    开开心心过生活、踏踏实实做技术
    Android-理解Intent
  • 原文地址:https://www.cnblogs.com/feiqiangsheng/p/15930614.html
Copyright © 2020-2023  润新知