我是编程新手。我在看this回答并找到了 @SuppressWarnings 注释的可能值列表。但我无法弄清楚值(value)隐藏的用法。谁能帮我举个例子?
最佳答案
来自 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"
的原始值。
关于java - @SuppressWarnings ("hiding") 在 eclipse 中的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31624073/