File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Returning function using instance variable" Watch "Returning function using instance variable" New topic
Author

Returning function using instance variable

Eshwar Prasad
Ranch Hand

Joined: Mar 21, 2008
Posts: 202

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: http://aspose.com/file-tools
 
subject: Returning function using instance variable
 
Similar Threads
help with global array
reading a user chosen file into array - multiple files
reading a user chosen file into array
problem with inserting data in a same column using prepared statement
Global Array not working