The use of “this” in Java

后端 未结 13 1925
-上瘾入骨i
-上瘾入骨i 2020-12-09 21:58

If I write the following class:

public class Example {

      int j;
      int k;

      public Example(int j, int k) {
           j = j;
           k = k;
          


        
13条回答
  •  [愿得一人]
    2020-12-09 22:41

    To avoid this, use an IDE (like Eclipse) and it will generate warnings in this case.

    Also, make your fields final unless they absolutely can't be. There are a number of reasons (apart from this one) to do that.

提交回复
热议问题