zoukankan      html  css  js  c++  java
  • 装箱拆箱陷阱记录

    1 陷阱一

    • java
    List<Short> list = new ArrayList<>();
    list.add((short) 4);
    boolean contains1 = list.contains(4); // false
    boolean contains2 = list.contains((short)4); // true
    
    • 字节码
      Code:
           0: new           #2                  // class java/util/ArrayList
           3: dup
           4: invokespecial #3                  // Method java/util/ArrayList."<init>":()V
           7: astore_1
           8: aload_1
           9: iconst_4
          10: invokestatic  #4                  // Method java/lang/Short.valueOf:(S)Ljava/lang/Short;
          13: invokeinterface #5,  2            // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
          18: pop
          19: aload_1
          20: iconst_4
          21: invokestatic  #6                  // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
          24: invokeinterface #7,  2            // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
          29: istore_2
          30: aload_1
          31: iconst_4
          32: invokestatic  #4                  // Method java/lang/Short.valueOf:(S)Ljava/lang/Short;
          35: invokeinterface #7,  2            // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
          40: istore_3
          41: return
    
  • 相关阅读:
    toj4119HDFS
    hdu2952Counting Sheep
    hdu2393Higher Math
    hdu2317Nasty Hacks
    hdu2309ICPC Score Totalizer Software
    hdu2304Electrical Outlets
    hdu2399GPA
    一、 软件测试概述
    JQuery选择器大全
    如何避免jQuery库和其他库的冲突
  • 原文地址:https://www.cnblogs.com/linzhanfly/p/9772429.html
Copyright © 2011-2022 走看看