Actually you can't call a method on A, only a method in the Interface, for
example
public interface Foo {
public int getInt();
}
public class A implements Foo {
public int getInt () {
return 10;
}
public String getString () {
return "ten";
}
}
public class B implements Foo {
public int getInt () {
return 20;
}
public double getFloat () {
return 20.0;
}
}
public class Main {
public static void main (String[] args) {
Foo a = new A();
Foo b = new B();
System.out.println("a + b = " + (a.getInt() + b.getInt()));
}
}
Would print out: a + b = 30. But with a and b being of type Foo, they only
recognize the getInt method, the A.getString and B.getFloat methods are
inaccessible without a cast. Hope this clears it up.
(*Chris*)
----- Original Message -----
From: Revathy Ravi <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, March 25, 1999 11:58 PM
Subject: Runtime information
> Hello everybody,
> The situation is like this.
>
> I have an interface say I . I have two classes, say A and B which
> implement this interface.
> I pass one of the object (say A) of these two classes in the session
> object. In the receiving servlet, I should be able to call the method of A
> without type casting or without checking.
>
> i.e., if I say Object o = session.getValue("A");
> o.functionofA();
> How to do this?
>
>
>
> Revathy R.
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html