@SuppressWarnings("hiding") 在 eclipse 中的目的是什么?
What is the purpose of @SuppressWarnings("hiding") in eclipse?
我是编程新手。我正在查看 this 答案并找到 @SuppressWarnings 注释的可能值列表。但我无法弄清楚值 hiding 的用法。谁能帮我举个例子?
来自 xyzws、
A class can declare a variable with the same name as an inherited variable from its parent class, thus "hiding" or shadowing the inherited version. (This is like overriding, but for variables.)
所以隐藏基本上意味着您已经创建了一个与继承作用域中的变量同名的变量,并且警告只是让您知道您已经完成了(如果您需要访问继承变量和局部变量)。
一个例子是:
public class Base {
public String name = "Base";
public String getName() { return name; }
}
public class Sub extends Base {
public String name = "Sub";
public String getName() { return name; }
}
在此示例中,Sub
隐藏了 Base
给出的 name
的值及其自身的值 - "Sub"
。 Eclipse 会警告您 - 以防万一您需要变量的原始值 name
- "Base"
.
我是编程新手。我正在查看 this 答案并找到 @SuppressWarnings 注释的可能值列表。但我无法弄清楚值 hiding 的用法。谁能帮我举个例子?
来自 xyzws、
A class can declare a variable with the same name as an inherited variable from its parent class, thus "hiding" or shadowing the inherited version. (This is like overriding, but for variables.)
所以隐藏基本上意味着您已经创建了一个与继承作用域中的变量同名的变量,并且警告只是让您知道您已经完成了(如果您需要访问继承变量和局部变量)。
一个例子是:
public class Base {
public String name = "Base";
public String getName() { return name; }
}
public class Sub extends Base {
public String name = "Sub";
public String getName() { return name; }
}
在此示例中,Sub
隐藏了 Base
给出的 name
的值及其自身的值 - "Sub"
。 Eclipse 会警告您 - 以防万一您需要变量的原始值 name
- "Base"
.