Java Mailing List Archive

http://www.junlu.com/

Google
Google
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
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
Urgent - Alternatives for Using Reflection

Urgent - Alternatives for Using Reflection

2004-08-04       - By Jaise George

 Back
Reply:     1     2     3     4     5     6     7     8  

Hi Shiva,

If you do not know what methods are there in the class, then I think
reflection is the only way. Reflection is meant for that only. As I said
in my previous mail, reflection is not a costly issue now. Methods in
java.lang.Class Source code of java.lang.Class uses reflection.

If you use an interface or any other implementation like that, you MUST
KNOW the method names in the class.

If decided to use an interface, you can go for a factory pattern here.

Class ABC implements InterfaceA, InterfaceB, InterfaceC
{
}

Interface InterfaceA{
       public string GetA();
}

Interface InterfaceB{
       public string GetB();
}

Now use a factory class to return the appropriate interface downcasted
from Class ABC. Call the method from the object.
This alleviates the discomfort you might have in using if-else
statements.

Hope this helps.

Regards
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:48 PM
To: J2EE-INTEREST@(protected)
Subject: Re: Urgent - Alternatives for Using Reflection


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.

}


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".

©2008 junlu.com - Jax Systems, LLC, U.S.A.