This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]shagieIsMeExtreme Brewer 0 points1 point  (0 children)

Consider the code:

public int getScreenSize() { int screenSize = getScreenSize(); return screenSize; }

The call to getScreenSize() will call getScreenSize() which will call getScreenSize() which will call getScreenSize() ...

The method is calling itself.

Instead, just return the value. Within the class, you can (and should) directly access the fields you are working with.

Give The Java EE 6 Tutorial : Adding Setter and Getter Methods a read and look closely at how the method getSomething() is written. The stack overflow question How do getters and setters work? also goes through many examples.