src/share/classes/java/lang/Byte.java

Print this page
rev 4568 : 7088952: Add "BYTES" constant to primitive wrapper classes
7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
Reviewed-by: smarks


  45 
  46     /**
  47      * A constant holding the minimum value a {@code byte} can
  48      * have, -2<sup>7</sup>.
  49      */
  50     public static final byte   MIN_VALUE = -128;
  51 
  52     /**
  53      * A constant holding the maximum value a {@code byte} can
  54      * have, 2<sup>7</sup>-1.
  55      */
  56     public static final byte   MAX_VALUE = 127;
  57 
  58     /**
  59      * The {@code Class} instance representing the primitive type
  60      * {@code byte}.
  61      */
  62     public static final Class<Byte>     TYPE = (Class<Byte>) Class.getPrimitiveClass("byte");
  63 
  64     /**












  65      * Returns a new {@code String} object representing the
  66      * specified {@code byte}. The radix is assumed to be 10.
  67      *
  68      * @param b the {@code byte} to be converted
  69      * @return the string representation of the specified {@code byte}
  70      * @see java.lang.Integer#toString(int)
  71      */
  72     public static String toString(byte b) {
  73         return Integer.toString((int)b, 10);
  74     }
  75 
  76     private static class ByteCache {
  77         private ByteCache(){}
  78 
  79         static final Byte cache[] = new Byte[-(-128) + 127 + 1];
  80 
  81         static {
  82             for(int i = 0; i < cache.length; i++)
  83                 cache[i] = new Byte((byte)(i - 128));
  84         }


 434      * </pre>
 435      *
 436      * @param  x the first {@code byte} to compare
 437      * @param  y the second {@code byte} to compare
 438      * @return the value {@code 0} if {@code x == y};
 439      *         a value less than {@code 0} if {@code x < y}; and
 440      *         a value greater than {@code 0} if {@code x > y}
 441      * @since 1.7
 442      */
 443     public static int compare(byte x, byte y) {
 444         return x - y;
 445     }
 446 
 447     /**
 448      * The number of bits used to represent a {@code byte} value in two's
 449      * complement binary form.
 450      *
 451      * @since 1.5
 452      */
 453     public static final int SIZE = 8;








 454 
 455     /** use serialVersionUID from JDK 1.1. for interoperability */
 456     private static final long serialVersionUID = -7183698231559129828L;
 457 }


  45 
  46     /**
  47      * A constant holding the minimum value a {@code byte} can
  48      * have, -2<sup>7</sup>.
  49      */
  50     public static final byte   MIN_VALUE = -128;
  51 
  52     /**
  53      * A constant holding the maximum value a {@code byte} can
  54      * have, 2<sup>7</sup>-1.
  55      */
  56     public static final byte   MAX_VALUE = 127;
  57 
  58     /**
  59      * The {@code Class} instance representing the primitive type
  60      * {@code byte}.
  61      */
  62     public static final Class<Byte>     TYPE = (Class<Byte>) Class.getPrimitiveClass("byte");
  63 
  64     /**
  65      * Returns a hash code for a {@code byte} value; compatible with
  66      * {@code Byte.hashCode()}.
  67      *  
  68      * @since 1.8
  69      *
  70      * @return a hash code value for a {@code byte} value.
  71      */
  72     public static int hashCode(byte value) {
  73         return (int)value;
  74     }
  75 
  76     /**
  77      * Returns a new {@code String} object representing the
  78      * specified {@code byte}. The radix is assumed to be 10.
  79      *
  80      * @param b the {@code byte} to be converted
  81      * @return the string representation of the specified {@code byte}
  82      * @see java.lang.Integer#toString(int)
  83      */
  84     public static String toString(byte b) {
  85         return Integer.toString((int)b, 10);
  86     }
  87 
  88     private static class ByteCache {
  89         private ByteCache(){}
  90 
  91         static final Byte cache[] = new Byte[-(-128) + 127 + 1];
  92 
  93         static {
  94             for(int i = 0; i < cache.length; i++)
  95                 cache[i] = new Byte((byte)(i - 128));
  96         }


 446      * </pre>
 447      *
 448      * @param  x the first {@code byte} to compare
 449      * @param  y the second {@code byte} to compare
 450      * @return the value {@code 0} if {@code x == y};
 451      *         a value less than {@code 0} if {@code x < y}; and
 452      *         a value greater than {@code 0} if {@code x > y}
 453      * @since 1.7
 454      */
 455     public static int compare(byte x, byte y) {
 456         return x - y;
 457     }
 458 
 459     /**
 460      * The number of bits used to represent a {@code byte} value in two's
 461      * complement binary form.
 462      *
 463      * @since 1.5
 464      */
 465     public static final int SIZE = 8;
 466 
 467     /**
 468      * The number of bytes used to represent a {@code byte} value in two's
 469      * complement binary form.
 470      *
 471      * @since 1.8
 472      */
 473     public static final int BYTES = Byte.SIZE / Byte.SIZE;
 474 
 475     /** use serialVersionUID from JDK 1.1. for interoperability */
 476     private static final long serialVersionUID = -7183698231559129828L;
 477 }