cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Soddemann <Thomas.Soddem...@rzg.mpg.de>
Subject Re: interface implementation
Date Fri, 12 Aug 2005 07:18:48 GMT
Hi Gunter

Since B extends A you cannot cast A to B unless the object casted is
originally indeed of type B.
...
A aParam = new A();
B bParam = new B();
C c = new C();

c.foo(bParam); // will work
c.foo(aParam); // class cast exception
...

If you really need to do something like that, you can either catch the
exception and handle it, or find out if the parameter is maybe of type B
and handle other types separately.

Thomas

Gunter D'Hondt wrote:

>I'm currently trying to use polymorphism but I'm always getting a 
>ClassCastException:
>
>--------------------------
>public class A {}
>public class B extends A {}
>public class C {
>        public void foo(A a) {
>                B b = new B();
>                b = (B) a;
>        }
>}
>--------------------------
>How am I doing wrong here?
>
>Regards,
>Gunter
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message