aspose file tools
The moose likes Beginning Java and the fly likes Returning function using instance variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Returning function using instance variable" Watch "Returning function using instance variable" New topic

Returning function using instance variable

Skanda Raman
Ranch Hand

Joined: Mar 21, 2008
Posts: 205

I have requirement to return different values from a function based on values passed to constructor.

For instance, the values passed to constructor would be opt1,opt2 and opt3. In this case the method test should return respective option values as shown in the program.

I have written the below code, but am not sure if the code could be written still more efficiently by using constructors.

please let me know if you have any suggestions.

Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
You should use an enum rather than String for your instance variable.

It safer and you can easily use a switch statement.

JDBCSupport - An easy to use, light-weight JDBC framework -
I agree. Here's the link:
subject: Returning function using instance variable