getter : Java Glossary

go to home page G words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish 2007-09-09 by Roedy Green ©1996-2009 Canadian Mind Products
index page for letter ⇒ punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
getter
An instance method that simple retrieves a value from the object instance. e.g.
The advantage of a getters is you can later add code to decompress, cache or modify the value, without changing any of the client code. Further, getters can mask the fact the retrieved value is virtual, calculated from other fields.

Eiffel lets you write getters even when the client code is tersely written as if the values were instance variables. However, Java insists on fluffy syntax both where the getter is defined and invoked.

Modern IDEs such as IntelliJ Idea will compose a set of getters and setters for you, given just the private instance variables.

Normally within a class you don’t usually use the getters; you go direct to the underlying instance variables, though sometimes it makes sense from a maintenance point of view to channel through getters. Within a package or from outside, you would nearly always go through getters rather than going to directly to public instance variables.


CMP homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.62] The information on this page is for non-military use only.
You are visitor number 2,738. Military use includes use by defence contractors.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/getter.html J:\mindprod\jgloss\getter.html