CNI vs interfaces

Mo DeJong mdejong@cygnus.com
Wed Aug 2 21:23:00 GMT 2000


>Nor is this something you can do in Java.
> -- 
> --Per Bothner
>per@bothner.com http://www.bothner.com/~per/

On Thu, 3 Aug 2000, Bryce McKinlay wrote:
>> Huh? As far as I know, this is not something you can do with Java either. Or
> do I misunderstand your example?
>> regards
>> [ bryce ]

Huh. I could have sworn that worked. Now I am
wondering why I thought that. I ran this example
and got a runtime cast exception.
interface I1 {
 void foo();
}
interface I2 {
 void foo();
}
public class ICast implements I2 {
 public void foo() { System.out.println("Called ICast.foo"); }
 public static void main(String[] args) {
 I2 itwo = new ICast();
 call( (I1) itwo );
 }
 static void call(I1 ione) {
 ione.foo();
 }
}
% java ICast
Exception in thread "main" java.lang.ClassCastException: ICast
Is runtime casting to a compatible interface something that
is supported in JDK 1.3? I could have sworn I read about
something like this somewhere, perhaps I am just confused.
Mo DeJong
Red Hat Inc


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /