Do the words to, as and get have any special meaning when used in method names?



new Integer(4).toString()





The term as is often used to denote that the method casts the item from one type to another, without creating a new object.

The term to often indicates that the method creates a new representation of the value as a new object of a different type.

The term get, along with set in Java EE has a special meaning as getters and setters, which are simply access and modify methods respectively to a private field. However, there does sometimes exist the convention in a wider sense of get indicating an existing value is returned and create indicates a new value is created.

And then there are many many situations where none of the above applies and as is used to create new objects, to just does a cast, get creates something etc.

So beyond get in the Java EE context, the answer to "do the words to, as and get have any special meaning when used in method names?", the answer is "sometimes".

  • sometimes in in other words, It depends on the developer's ability to name things. So, no, they don't have special meaning but the one the developer had in mind. Your answer sounds a convention to me, and I like It, however I have never read it as a Java naming/style convention. Do you have any reference or link to share? – Laiv Apr 25 '18 at 6:31
  • @Laiv, Having had a look, it may well be a convention that I've picked up over time. For example, looking at the link that Deduplicator provides in his comment to the question has answers that are all over the place. – David Arno Apr 25 '18 at 8:26
  • Good enough. Looks like there's a sort of agreement around the premises you introduced. I gather this sort of "resources" for me to have some guidelines to follow during the development. Thank you! – Laiv Apr 25 '18 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.