Suppose I have a class called Person:
public class Person
{
private String name, ID, location;
}
Instead of writing individual accessors for name, ID, and location, is there anyway to do something like this:
public String get%s
{
return this.%s
}
Where “%s” stands as a sort of place holder for the name of the String which I want to “get”. This way, for the sake of convenience and efficiency, I will be able to write one method to access all three Strings. Thanks.
Java doesn’t have this feature, but if you use Eclipse, you can automatically generate setters and getters for your class members.