您在静态变量setter方法中使用什么名称作为参数?

时间:2022-06-24 23:04:31

When I write setters for instance methods, I use this to disambiguate between the instance variable and the parameter:

当我为实例方法编写setter时,我使用它来消除实例变量和参数之间的歧义:

public void setValue(int value) {
  this.value = value;
}

So, what do I do when value is a class variable (static) instead of a member of an instance?

那么,当value是类变量(静态)而不是实例的成员时,我该怎么办?

private static int value = 7;
public static void setValue(int value) {
  value = value;  // compile fails; ambiguous
}

1 个解决方案

#1


Use <classname>.value = value;

使用 .value = value;

#1


Use <classname>.value = value;

使用 .value = value;