黑马程序员技术交流社区

标题: int.class 和Integer.class的区别 [打印本页]

作者: 叶涛    时间: 2011-10-13 18:25
标题: int.class 和Integer.class的区别
int.class 和Integer.class的区别?什么时候用Integer.class?
作者: 敖东    时间: 2011-10-13 19:22
int和Integer之间是简单类型和包装类之间的关系。
但这两个的class对象则没有太多的关系,是Class类的两个不同实例而已。

作者: 苏志伟    时间: 2011-10-13 19:33
The Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.

简单说是一个聚合关系,我也是查资料的.
  1. package java.lang;  
  2.   
  3. public final class Integer extends Number implements Comparable<Integer> {  
  4.   
  5.     private final int value;  
  6.   
  7.      public Integer(int value) {  
  8.           this.value = value;  
  9.      }  
  10. }  
复制代码
上边的是其实现的代码!
至于什么是后用Integer,举个例子:当你想用到integer类中的一些方法的时候,你就得用到它。
作者: 贾双涛    时间: 2011-10-13 20:11
int是基本的数据类型,不是java类的的类型,而有时候必须要使用java类的类型,所以每一种基本的数据类型都有一个与之对应的包装类,这两个类型是不同的类型,所以当用.class获得其在内存中对应的字节码文件时,返回值是不同的。
至于什么时候用Integer.class,那就是当你需要获得Integer类型的那份字节码时就需要用Integer.class,当你需要获得int类型的那份字节码时就用int.class
作者: 颜庭飞    时间: 2011-10-13 20:15
int属于基本数据类型,与double,float等是一个级别的
Integer是包装类,是引用类型,跟你自己定义的Student,Person,Dog类是一样的。
看你需要哪个类型的字节码就用哪个喽~~




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2