说说Java中的 + 运算符 | bit-knowledge



说说Java中的 + 运算符 | bit-knowledge

局部变量中的 + (代码1) public void process() { int a = 0; a = a + 1; // (1) a += 1; // (2) a++; // (3) } 代码1中,(1), (2), (3)都实现对变量 a 的加1操作,但是细节方面有细微差异。我们看下编译后的代码: public void process(); Code: // int a = 0; 0: iconst_0 1: istore_1 // a = a + 1; 2: iload_1 3: iconst_1 4: iadd 5: istore_1 // a += 1; 6: iinc 1, 1 // a++; 9: iinc 1, 1 12: return 分析反编译代码我们可以发现, 而 所以实际编码中用 实例变量中的 + (代码2) public class Plus { private int a = 0; public void process() { a = a + 1; // (1) a += 1; // (2) a++; // (3) } } 编译后的字节码 public void process(); Code: // a = a + 1; // stack[this] 0: aload_0 // stack[this, this] 1: aload_0 // stack[this, a] 2: getfield #2 // Field a:I // stack[this, a, 1] 5: iconst_1 // stack[this, a + 1] 6: iadd // stack[] this.a = a + 1 7: putfield #2 // Field a:I // a += 1; // stack[this] 10: aload_0 // stack[this, this] 11: dup // stack[this, a] 12: getfield #2 // Field a:I // stack[this, a,

Read full article from 说说Java中的 + 运算符 | bit-knowledge


No comments:

Post a Comment

Labels

Algorithm (219) Lucene (130) LeetCode (97) Database (36) Data Structure (33) text mining (28) Solr (27) java (27) Mathematical Algorithm (26) Difficult Algorithm (25) Logic Thinking (23) Puzzles (23) Bit Algorithms (22) Math (21) List (20) Dynamic Programming (19) Linux (19) Tree (18) Machine Learning (15) EPI (11) Queue (11) Smart Algorithm (11) Operating System (9) Java Basic (8) Recursive Algorithm (8) Stack (8) Eclipse (7) Scala (7) Tika (7) J2EE (6) Monitoring (6) Trie (6) Concurrency (5) Geometry Algorithm (5) Greedy Algorithm (5) Mahout (5) MySQL (5) xpost (5) C (4) Interview (4) Vi (4) regular expression (4) to-do (4) C++ (3) Chrome (3) Divide and Conquer (3) Graph Algorithm (3) Permutation (3) Powershell (3) Random (3) Segment Tree (3) UIMA (3) Union-Find (3) Video (3) Virtualization (3) Windows (3) XML (3) Advanced Data Structure (2) Android (2) Bash (2) Classic Algorithm (2) Debugging (2) Design Pattern (2) Google (2) Hadoop (2) Java Collections (2) Markov Chains (2) Probabilities (2) Shell (2) Site (2) Web Development (2) Workplace (2) angularjs (2) .Net (1) Amazon Interview (1) Android Studio (1) Array (1) Boilerpipe (1) Book Notes (1) ChromeOS (1) Chromebook (1) Codility (1) Desgin (1) Design (1) Divide and Conqure (1) GAE (1) Google Interview (1) Great Stuff (1) Hash (1) High Tech Companies (1) Improving (1) LifeTips (1) Maven (1) Network (1) Performance (1) Programming (1) Resources (1) Sampling (1) Sed (1) Smart Thinking (1) Sort (1) Spark (1) Stanford NLP (1) System Design (1) Trove (1) VIP (1) tools (1)

Popular Posts