I have a variable called
List<String> names;
if i have a method like
Iterator getNames()
{
return names.iterator();
}
Is it technically still a getter method because i changed it to Iterator?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Even though the JDK allows this, its not a good idea to do it.
For one, there are conventions based off of the naming of your methods, that have some dependencies on them.
JavaBean objects use getters and setters to set bean properties. If they disobey the convention, the program will fail. See JavaBeans spec, section 8.3.1
JSON objects – the JSONObject class uses the accessor methods in the constructor.
See: http://www.json.org/javadoc/org/json/JSONObject.html#JSONObject(java.lang.Object)
Some JPA implementations will incorrectly process your entity classes if they have multiple getters with the same name but different return types.
I bet there are more dependencies, but even if these don’t apply to your solution, it’s still wise to follow the convention for the sake of readability. You don’t want any other developer cursing you sometime in the future for breaking the standards 🙂