What is the purpose of @SuppressWarnings ("hiding") in eclipse?

I am new to programming. I looked at this answer and found a list of possible values ​​for the @SuppressWarnings annotation. but I cannot understand the use of the meaning of concealment . Can someone help me with an example?

+7
java eclipse annotations
source share
1 answer

From xyzws ,

A class can declare a variable with the same name as an inherited variable from its parent class, thus β€œhiding” or obscuring the inherited version. (This is similar to overriding, but for variables.)

So hiding basically means that you created a variable with the same name as the variable from the inherited scope, and the warning just lets you know that you did it (in case you need access to the inherited variable as well as the local variable )

Example:

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; } } 

In this example, Sub hides the name value specified by Base , with its own value, "Sub" . Eclipse will warn you - just in case you need the original value of the name variable - "Base" .

+9
source share

All Articles