2016-10-05 121 views
3

的发电机我有接口答:GWT类继承接口

public interface A{ 
    String someMethod(); 
} 

并采用GWT.create(的A.class)我得到实现此接口的瞬间。

但是,如果我创建接口B();

public interface B extends A{ 
    String someOtherMethod(); 
} 

并做GWT.create(B.class)我得到B接口的实现,但没有实现A接口方法。

并获得编译错误:

[错误] 3号线:类型B_impl必须实现抽象方法A.someMethod()

附加: 后来我才发现,可它与连接注释。

所以我有:

public interface annotationHelperClass{ 
} 

有:

public final class annotationHelperClassGenerator{ 
//Some code 
} 

注释:

@Retention(RetentionPolicy.RUNTIME) 
@Target(ElementType.METHOD) 
public @interface MyAnnotation { 
    String someParam(); 
} 

这样一个接口将是:

public interface A extends annotationHelperClass{ 
     @MyAnnotation(someParam = "Some string") 
     String someMethod(); 
    } 

接口B:

public interface B extends A{ 
     @MyAnnotation(someParam = "Some another string") 
     String someOtherMethod(); 
    } 
+0

GWT.create(B.class)允许你创建一个接口? –

+0

不,它允许我创建此接口的即时,但仅限于在B接口中声明的方法。 –

+0

可能是Annotations中的原因,我使用接口A中的注释来帮助我生成实现类,但注释不会继承到B接口,所以GWT无法正确生成该方法! –

回答

0

的问题是,我的发电机使用:

for (JMethod method : targetClass.getMethods()) { 
    MyAnnotation descriptor = method.getAnnotation(MyAnnotation.class); 
     JParameter[] parameters = method.getParameters(); 
     //some code 
} 

所以改变的getMethods()上getInheritableMethods()解决了这个问题。

对不起,我不确定在这种情况下什么是重要的!