Reputation: 1005
For the unused members eclipse give me a warning "The value of the field is not used" with private access modifier. If modifier has been changed to public or no modifier then there is no warning.
This is create confusion for me. Default modifier is not public in java. Eclipse change the warning if modifier has been changed to private and no modifier. There must be difference.
Upvotes: 1
Views: 560
Reputation: 32914
The reason Eclipse issues the warning only for private members is because that's the only situation in which Eclipse can determine with certainty whether the member is unused or not. Eclipse only knows about the code that exists in the same workspace, so it can't determine if public
, protected
, or "default" visible members are used by other code outside the current workspace. private
members can't possibly be used outside the class, so Eclipse can make the "unused" determination.
Upvotes: 1
Reputation: 5787
private - Only the class itself can access it
package-private - No modifier is assigned. Only classes in the same package can access it
Upvotes: 4
Reputation: 121998
If a class has no modifier (the default, also known as package-private), it is visible only within its own package. So the variable have a chance to use in other classes.
Where as private means you can use it only in the same class. If you are not using it in the same class, there is no use of it at all and your IDE is telling the same.
Upvotes: 1
Reputation: 1479
The default modifier is also called 'package-private', meaning only classes in the same package can access it.
Upvotes: 4