读JDK源码---之NUMBER

阅读更多
Number是一个抽象类,他是BigDecimal,BigInteger,Byte,Double,Float,Integer,Long,Short的父类
他提供以下抽象方法:
1、public abstract int intValue();
该方法把此对象所代表的值转换为int

2、public abstract long longValue();
该方法把此对象所代表的值转换为long

3、 public abstract float floatValue();
该方法把此对象所代表的值转换为float

4、public abstract double doubleValue();
该方法把此对象所代表的值转换为double

提供以下方法:
1、把此对象代表的值值转换为byte,这里使用了模板方法
public byte byteValue() {
return (byte)intValue();
    }


2、把此对象代表的值值转换为short,这里使用了模板方法
  public short shortValue() {
return (short)intValue();
    }


Number类中主要应用模板方法模式

你可能感兴趣的:(读JDK源码---之NUMBER)