简体   繁体   English

您如何编写自己的Java类以继承JFC和WFC类?

[英]How would you write your own Java classes to inherit from both JFC and WFC classes?

As we all know "multiple inheritance" is prohibited in Java and J#. 众所周知,Java和J#中禁止“多重继承”。 However, you can implement multiple interfaces like Runnable using Java and J#. 但是,您可以使用Java和J#实现多个接口,如Runnable。 So, how would you write your own classes to inherit from both JFC and WFC classes, and implement both JFC and WFC interfaces at the same time ? 那么,如何编写自己的类来继承JFC和WFC类,并同时实现JFC和WFC接口? Is something like that possible......? 这样的事情可能......?

I know how to inherit JFC and WFC classes seperately and implement interfaces one at a time. 我知道如何单独继承JFC和WFC类并一次实现一个接口。 Could someone post a sample code ? 有人可以发布示例代码吗? I am reading John Sharp's Microsoft Press book, and he says all that is elementary...... Can anyone help ? 我正在阅读John Sharp的微软出版社的书,他说所有这些都是基本的......任何人都可以帮忙吗?

class FooBooImpl implements Foo, Boo {
    public void iAmFoo() {
       // do Foo#iAmFoo
    }
    public void iAmBoo() {
       // do Boo#iAmBoo
    }
}

or 要么

class FooBooImpl extends Foo implements Boo {
    @Override
    public void iAmFoo() {
       super.iAmFoo();
       // do something
    }

    public void iAmBoo() {
       // do Boo#iAmBoo
    }
}

or (if you decided to delegate) 或(如果您决定委托)

class SuperFooBoo {
    private Foo foo;
    private Boo boo;

    public void iAmFoo() {
       foo.iAmFoo();
    }

    public void iAmBoo() {
       boo,iAmBoo();
    }
}

Now you main limitation here would be if Foo and Boo define method of the same signature. 现在你主要的限制是如果Foo和Boo定义相同签名的方法。 You have to be careful mixing JFC and WFC (if they can be mixed, I don't really know) both of these are toolkits that hook into native code. 你必须小心混合JFC和WFC(如果它们可以混合,我真的不知道)这两个都是挂钩到本机代码的工具包。

As Droidln.net said, you just create the class and say it implements the two interfaces. 正如Droidln.net所说,你只需创建类并说它实现了两个接口。 Then you write the methods matching those described in the interface. 然后编写与接口中描述的方法匹配的方法。

If you use eclipse (and I assume most other IDEs), you can automatically create the required methods. 如果您使用eclipse(我假设大多数其他IDE),您可以自动创建所需的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM