Integer integer = 1; int unboxing = integer++;
1: invokestatic // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; 8: invokevirtual // Method java/lang/Integer.intValue:()I 11: iconst_1 12: iadd 13: invokestatic // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; 21: invokevirtual // Method java/lang/Integer.intValue:()I
// 简单明了 public class Counter { private final AtomicLong counter = new AtomicLong(); public void increase() { counter.incrementAndGet(); } }
// 复杂 public class CompactCounter { private volatile long counter; private static final AtomicLongFieldUpdater<CompactCounter> UPDATER = AtomicLongFieldUpdater.newUpdater(CompactCounter.class, "counter"); public void increase() { UPDATER.incrementAndGet(this); } }
private final int value;
// Integer @Native public static final int SIZE = 32; public static final int BYTES = SIZE / Byte.SIZE; // Byte public static final int SIZE = 8;
转载请注明出处:http://zhongmingmao.me/2019/05/04/java-core-int-Integer/
访问原文「 Java核心 -- int和Integer 」获取最佳阅读体验并参与讨论