Number类
WrapperDemo.java
package test.wrap; public class WrapperDemo{ public static void main(String args[]){ int x = 30 ; // 基本数据类型 Integer i = new Integer(x) ; // 装箱:将基本数据类型变为包装类 float temp = i.floatValue() ;// 拆箱:将一个包装类变为基本数据类型 System.out.println(temp); // 30.0 } };
运行结果30.0。Integer继承于Number,因此可以使用继承方法floatValue()。