  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Struts - A MVC web framework | | Tomcat - JSP/Servlet container | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | | JSP - A mailing list about Java Server Pages specification and reference | |
Struts & Hibernate
|
|
|
  | | | Urgent - Alternatives for Using Reflection | Urgent - Alternatives for Using Reflection 2004-08-03 - By Michael New
Back From: "Shivprasad_Bade" <Shivprasad_Bade@(protected)> > Thanx Jaise for quick reply, > > Here is the details. > > I have a class. > > class ABC > { > private string a; > private string b; > private string c; > public string getA(){} > public string getB(){} > public string getC(){} > ... > ... > } > > Now in other class > > someMethod(String condition) > { > instance=new ABC(); > //now depending upon the condition I have to call either getA() getB() > or getC() and I don't > // know what methods are there in the class and I don't want to use the > reflection. > > }
Reflection will give you the methods the object has available, but you don't want to use it. And you don't want to use if.
You could you a case statement.
I can't think of any other way to do this without building a big framework. The simplest thing would be to use an "if" or a "case".
Mike > > > Hope it gives some idea to you. > And abt the interface solution I have given a thought to it but before that > just wanted to make sure there is no other way for doin this. > > - > > Regards, > > Have a nice day..!!! > > Shivprasad Bade > > > -- --Original Message-- -- > From: Jaise George [mailto:jaiseg@(protected)] > Sent: Tuesday, August 03, 2004 6:42 PM > To: J2EE-INTEREST@(protected) > Subject: Re: Urgent - Alternatives for Using Reflection > > > Hi Shiva, > > Your description is not clear enough to give a solution. If the methods of > that class is absolutely unknown, you can go for reflection. Reflection is > not that dangerous these days. I guess application servers use that > extensively. > > Alternatively an option I can you is to use an interface, if the class is > developed by your own team. > > Jaise > > -- --Original Message-- -- > From: A mailing list for Java(tm) 2 Platform, Enterprise Edition > [mailto:J2EE-INTEREST@(protected)] On Behalf Of Shivprasad_Bade > Sent: Tuesday, August 03, 2004 6:32 PM > To: J2EE-INTEREST@(protected) > Subject: Urgent - Alternatives for Using Reflection > > > Hi, > > Sorry for posting it on J2EE list ... > > Is there any alternative for using the Reflection. > > I have a class instance with me but want to call a method depending upon > some condition and I dont want to use the if-else etc. > > Thanx in advance > > > - > > Regards, > > Have a nice day..!!! > > Shivprasad Bade > > Logic will get you from A to B - imagination will take you anywhere. > ********************************************************************** ** > ** > This email (including any attachments) is intended for the sole use of the > intended recipient/s and may contain material that is CONFIDENTIAL AND > PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or > distribution or forwarding of any or all of the contents in this message is > STRICTLY PROHIBITED. If you are not the intended recipient, please contact > the sender by email and delete all copies; your cooperation in this regard > is appreciated. > ********************************************************************** ** > ** > > ====================================================================== == > === > To unsubscribe, send email to listserv@(protected) and include in the body > of the message "signoff J2EE-INTEREST". For general help, send email to > listserv@(protected) and include in the body of the message "help". > > ====================================================================== ===== > To unsubscribe, send email to listserv@(protected) and include in the body > of the message "signoff J2EE-INTEREST". For general help, send email to > listserv@(protected) and include in the body of the message "help". > ********************************************************************** **** > This email (including any attachments) is intended for the sole use of the > intended recipient/s and may contain material that is CONFIDENTIAL AND > PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or > distribution or forwarding of any or all of the contents in this message is > STRICTLY PROHIBITED. If you are not the intended recipient, please contact > the sender by email and delete all copies; your cooperation in this regard > is appreciated. > ********************************************************************** **** > > ====================================================================== ===== > To unsubscribe, send email to listserv@(protected) and include in the body > of the message "signoff J2EE-INTEREST". For general help, send email to > listserv@(protected) and include in the body of the message "help". >
=========================================================================== To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help".
|
|
 |