码迷,mamicode.com
首页 > 其他好文 > 详细

int 和 Integer区别

时间:2018-11-12 22:20:30      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:character   style   pre   ==   unbox   nbsp   app   OLE   1.5   

Java 是一个近乎纯洁的面向对象编程语言,但是为了编程的方便还是引入不是对象的基本数据类型,但是为了能够将这些基本数据类型当成对象操作,Java 为每一个基本数据类型都引入了对应的包装类型(wrapper class),int 的包装类就是 Integer,从 JDK 1.5 开始引入了自动装箱/拆箱机制,使得二者可以相互转换。

Java 为每个原始类型提供了包装类型:
原始类型: boolean,char,byte,short,int,long,float,double
包装类型:Boolean,Character,Byte,Short,Integer,Long,Float,Double

 1 package com.lovo;
 2 public class AutoUnboxingTest {
 3 public static void main(String[] args) {
 4 Integer a = new Integer(3);
 5 Integer b = 3; // 将3自动装箱成Integer类型
 6 int c = 3;
 7 System.out.println(a == b); // false 两个引用没有引用同一对象
 8 System.out.println(a == c); // true a自动拆箱成int类型再和c比较
 9 }
10 }

 

int 和 Integer区别

标签:character   style   pre   ==   unbox   nbsp   app   OLE   1.5   

原文地址:https://www.cnblogs.com/whirlwind/p/9949348.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!