2016-10-05 175 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()解決了這個問題。

對不起,我不確定在這種情況下什麼是重要的!