wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes @return Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "@return" Watch "@return" New topic


Lenny Peter
Ranch Hand

Joined: Apr 22, 2008
Posts: 52
Should I have return if I have jMembership = 1600?


When can I use only void get and when can I use both get and set in a class?
public getName()
public setName()
[ May 16, 2008: Message edited by: Leni Kravitskki ]
marc weber

Joined: Aug 31, 2004
Posts: 11343

A "get" method returns something (a value or reference), so it cannot have a return type of void.

As for when to use get/set... It depends entirely on whether you want to make these features available outside the class.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130
You either change your return type or return nothing.

Durga Prasad
marc weber

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Prasad Tamirisa:
...or return nothing.

Returning nothing will allow it to compile, but then what is the method "getting"?
subject: @return
Similar Threads
[Hibernate] Join without FK Relationship using Criteria
General Application Help
Why does this work? (apparent creation of an instance of an interface)
Comments on my first program to use an object