zoukankan      html  css  js  c++  java
  • 【7】 Java基础 <七> —— 自动装箱 自动拆箱

    封装类:

      包装类  将基本数据类型  包装成  类

      类  可以创建对象。(这样的设计符合面向对象的思想)

     

    自动装箱  Integer b = 10 ;   等同于  Integer i = new Integer(20) ;  将基本数据类型封装成对象

    自动拆箱  System.out.println( b + 20 ) ;   将对象转换为基本数据类型

     

    创建 Integer 对象时 ,系统会自动判断 Integer 的值有没有超过127 ,如果超过127会在堆内存空间开辟新的地址 ,如果没超过默认的是同一个对象。

    Integer a = 127;
    Integer b = 127;
    System.out.println(a.hashCode()+":::"+b.hashCode());
    System.out.println("a==b?:::"+(a==b));       true 没超127同一个对象
    Integer c = 128;
    Integer d = 128;
    System.out.println(c.hashCode()+":::"+d.hashCode());
    System.out.println("c==d?:::"+(c==d));       false 超过127 不同对象

    青春看起来如此完美, 没空闲去浪费时间。 <我们最后的话——刺猬>
  • 相关阅读:
    row_number() over
    hubbledotnet 使用笔记
    Sql 递归
    aspnet_isapi.dll 和 iis
    正则题目
    Html to jsstring
    js 回车提交表单
    with as
    MSSQL 时间的操作
    php 执行mssql 里的语句,报错 The EXECUTE permission was denied on the object
  • 原文地址:https://www.cnblogs.com/WangJing0506/p/8545955.html
Copyright © 2011-2022 走看看