Java – protects int, visible only to the specified method

Is there any way to make me invisible to other methods in the same class?

private int i;

private void updateI(int i) {
  this.i = i;
}

Solution

No – all members of the class are visible to each other

If you find that some members of your class should not access a specific member, it may indicate that you should separate your courses – consider whether you can better partition information Of course, this is not always a solution - of course, if you find that there are two or three interrelated fields and only some methods should be touched, it usually means that you should put them in your own type

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>