Java包含一个非常简单的享元模式

2012-11-12

  具体看如下代码

  public class AutoBox {

  /**

  * @param args

  */

  public static void main(String[] args) {

  // TODO Auto-generated method stub

  Integer i = 13;

  Integer j = 13;

  Integer i1 = 137;

  Integer j1 = 137;

  System.out.println(i == j );//true

  System.out.println(i1 == j1 );//false

  }

  }

  在java中 如果用到1字节以内的数字 它会把他缓存起来进行复用

分享到:
0
相关阅读
友情链接
© 2018 我考网 http://www.woexam.com 中国互联网举报中心 湘ICP备18023104号 京公网安备 11010802020116号
违法和不良信息举报:9447029@qq.com