McT*_*fik 11 java gwt parametric-polymorphism
我在抽象的java类中有以下代码:
protected abstract <E extends HasText & IsWidget> E createNewDisplayWidget();
Run Code Online (Sandbox Code Playgroud)
编译好.但是,如果我在任何地方调用它,编译器会抱怨:
Bound mismatch: The generic method createNewDisplayWidget() of type DemoClass is not applicable for the arguments (). The inferred type HasText is not a valid substitute for the bounded parameter <E extends HasText & IsWidget>
Run Code Online (Sandbox Code Playgroud)
有没有办法要求抽象方法返回应该实现多个接口的东西?
注意:不,我无法创建一个实现我喜欢的两个特殊界面.GWT有像Label这样的小部件已经实现了所谓的接口,我想使用这个小部件.
编辑:我从这里想到了这个想法(第22页):