CNI vs interfaces

Mo DeJong mdejong@cygnus.com
Wed Aug 2 20:55:00 GMT 2000


On Thu, 3 Aug 2000, Bryce McKinlay wrote:
> Tom Tromey wrote:
>> > Bryce> One way might be to make a dummy "JInterface" C++ class and
> > Bryce> have gcjh make interfaces inherit from this in addition to
> > Bryce> java.lang.Object. Would this work? Or is there a better option?
> >
> > One option would be to treat interfaces via real multiple inheritance,
> > and change g++ to generate the appropriate call for Java objects whose
> > class uses MI. This might be hairy.
> >
> > Another choice would be an attribute on the class. This is probably
> > more straightforward, but also more hacky.
>> I'm thinking an __attribute__ (also suggested by Glenn Chambers) would
> work nicely. The C++ compiler already recognises a "com_interface"
> attribute, so a "java_interface" would be keeping consistent with that.
>> We'll still need to use multiple inheritance, as interfaces can have
> multiple superinterfaces (currently gcjh doesn't "see" these). Also need
> to make sure that the compiler allows assignment from a class field to a
> compatible interface field.
>> Is the vtable lookup emitted by C++ for a java.lang.Object method call
> going to work if the compiler sees multiple inheritance (I have no idea
> how MI dispatch works)?

How would the use of C++ multiple inheritance deal with the case
where a Java interface is casted to an interface that is not
inherited?
// File ICast.java
interface I1 {
 void foo();
}
interface I2 {
 void foo();
}
public class ICast implements I2 {
 public void foo() {}
 void bar() {
 I2 itwo = new ICast();
 I1 ione = (I1) itwo;
 ione.foo();
 }
}
As far as I know, this is something you can not do with
pure vitual C++ classes.
Mo DeJong
Red Hat Inc


More information about the Java mailing list

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