• Java 源码 Byte


    介绍

    The Byte class wraps a value of primitive type byte in an object.

    示例

    public class Test {
      public static void main(String[] args) {
        Byte c = new Byte("120");
        System.out.println(c.toString());
      }
    }
    

    源码

    public final class Byte extends Number implements Comparable<Byte> {
    
      /**
       * -2<sup>7</sup>.
       */
      public static final byte MIN_VALUE = -128;
    
      /**
       * 2<sup>7</sup>-1.
       */
      public static final byte MAX_VALUE = 127;
    
      public static byte parseByte(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 (byte)i;
      }
    
      public static Byte valueOf(String s) throws NumberFormatException {
        return valueOf(s, 10);
      }
    
      private final byte value;
    
      public Byte(byte value) {
        this.value = value;
      }
      
      public byte byteValue() {
        return 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;
      }
    
      public String toString() {
        return Integer.toString((int)value);
      }
    
      public static int hashCode(byte value) {
        return (int)value;
      }
    
      public boolean equals(Object obj) {
        if (obj instanceof Byte) {
          return value == ((Byte)obj).byteValue();
        }
        return false;
      }
    
      public static int compare(byte x, byte y) {
        return x - y;
      }
    }
    
    
  • 相关阅读:
    2013年工作中遇到的20个问题:81-100
    2013年工作中遇到的20个问题:81-100
    码农:客户是恶魔
    码农:客户是恶魔
    C# DataGridView 使用
    Java实现 LeetCode 203 移除链表元素
    Java实现 LeetCode 203 移除链表元素
    Java实现 LeetCode 202 快乐数
    Java实现 LeetCode 202 快乐数
    Java实现 LeetCode 202 快乐数
  • 原文地址:https://www.cnblogs.com/feiqiangsheng/p/15928692.html
Copyright © 2020-2023  润新知