Use an interface
Create an interface lets call it 'Showable'

for example
public interface Showable {
              void doShow();
}

Have A, B and C implement this interface ...

for example:

public class A implements Showable {

...
        public void doShow() {

                //implementation in here
        }
}


That method then would change from:

 public void show(Object o) {
         o.doShow();
 }

                to

 public void show(Showable s) {
        s.doShow();
 }


Should work i think

Mark

> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Shawn Zhu
> Sent: Wednesday, November 22, 2000 3:55 PM
> To: [EMAIL PROTECTED]
> Subject: finally, something interesting!
>
>
> Scope: Java
> Q:
> if you have three class A, B, and C all have the same method doShow();
> We only know that all inherit from Class Object (like all other
> classes do).
>
> Is it possible to have a public function that takes in an Class
> Object that
> may belong
> to A, B, or C, and call doShow()?
>
> Something conception like:
>
> public void show(Object o) {
>         o.doShow();
> }
>
> Of course the above code won't compile.  One way to hack it is to use
> "InstanceOf" (one of the answer) but it's a unclean hack.
>
> Anyone has any better ideas?  I thought about going from
> Object.getClass(),
> but it does
> not seem to be the way.
>
> ==================================================================
> =========
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set
> JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to