Integer和int的区别,包装类,基本数据类型,区别
来源:互联网 发布:2015年度网络热词 编辑:程序博客网 时间:2024/05/02 01:53
int 是基本数据类型。Integer是其包装类,注意是一个类。
https://zhidao.baidu.com/question/322364721.html
----
包装类,和数据类型,使用上,有什么区别?下面举个例子:
int test0;
TestBean test2;//TestBean是我自定义的类test2.getName();//报错The local variable aa may not have been initialized
Integer test1;test1.byteValue();//报错The local variable aa may not have been initialized
1基本数据类型,不是类,即不是对象,即不能进行new这样来创建对象。所以其也就不能使用"对象.function()",其也就少了好多处理函数,很不方便。因此才有了封装类,没有封装类,好多数据都不能处理,很不方便。
比如我现在要用泛型
List<Integer> nums;
这里<>需要类。如果你用int。它会报错的,因为int是基本数据类型,不是类2类的对象必须初始化,即new才可以访问成员函数,否则访问成员函数报错。而基本数据类型,不是类,不能new,否则报错。
int bb=new int();//Syntax error on token "int", invalid ClassType
Integer test1;
test1.byteValue();//报错The local variable aa may not have been initialized
----
这里就牵扯出来另几个问题,①java基本数据类型有哪些?
http://www.cnblogs.com/simplefrog/archive/2012/07/15/2592011.html
②String是不是基本数据类型?
不是。因为基本数据类型不能new,更不可能有“对象.function”这种用法。
String test = new String();//编译通过,不报错
----------在此总结,java的变量,有几种类型?
1基本数据类型,int、float等8种。不用new,new会报错。
2Class,即类。可以使用Test test=new Test();这种“对称”初始化的方式,进行new。
3Interface,即接口。不可以使用Test test=new Test();这种“对称”初始化的方式,进行new。会报错。
必须非对称,要用接口的实现类,给接口new。
5数组。其new的方式也比较特殊,有如下三种,
所以,综上所述,是根据什么区分各种变量的类型的?是new的方式。
其实,我们发现,class、interface、数组这三者都要new,因此可以将interface、数组当成特殊的class看待,因此三者都可以当成是class。
- Integer和int的区别,包装类,基本数据类型,区别
- Integer与int的区别(包装类和基本数据类型的区别)
- int与Integer的区别-Java中的基本数据类型与包装类
- 基本数据类型和包装类的区别
- 面试题解析:4 包装类和原生数据类型的区别 例如:Integer 和 int的区别
- Java 基本数据类型和包装类的区别
- java基本数据类型&&int与Integer区别
- Java中的Integer和int等包装类和基本数据类型简单比较
- Java探秘之基本数据类型和包装类(int,Integer)(一)
- Integer类和int的区别
- int 和 Integer 的区别
- int 和 Integer 的区别
- int和Integer的区别
- int和Integer的区别
- int 和 integer的区别
- Integer和int的区别
- Integer 和 int 的区别
- int和integer的区别
- vs 中调用QT的动态连接库
- android实时视频网络传输方案总结(一共有五套)
- Hbuilder 使用技巧
- C++/MFC-几种常用控件
- python装饰器学习
- Integer和int的区别,包装类,基本数据类型,区别
- 深入 Spring 系列之静态资源处理
- py pandas 库
- host
- 最小二乘法
- Java过滤器与SpringMVC拦截器关系和区别、Java监听器
- Java基础知识总结
- 23种设计模式之单例模式(线程安全)
- maven netty spring项目打包jar报错解决办法!