首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

读JDK源码-之NUMBER

2012-10-08 
读JDK源码---之NUMBERNumber是一个抽象类,他是BigDecimal,BigInteger,Byte,Double,Float,Integer,Long,Sho

读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类中主要应用模板方法模式

热点排行