GWT 类 继承接口的生成器
GWT Classes generator of inherited interface
我有接口A:
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();
}
因此接口 A 将是:
public interface A extends annotationHelperClass{
@MyAnnotation(someParam = "Some string")
String someMethod();
}
接口 B:
public interface B extends A{
@MyAnnotation(someParam = "Some another string")
String someOtherMethod();
}
问题是我的生成器使用:
for (JMethod method : targetClass.getMethods()) {
MyAnnotation descriptor = method.getAnnotation(MyAnnotation.class);
JParameter[] parameters = method.getParameters();
//some code
}
所以在 getInheritableMethods() 上更改 getMethods() 解决了这个问题。
抱歉没有详细说明,我不确定在这种情况下什么是重要的!
我有接口A:
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();
}
因此接口 A 将是:
public interface A extends annotationHelperClass{
@MyAnnotation(someParam = "Some string")
String someMethod();
}
接口 B:
public interface B extends A{
@MyAnnotation(someParam = "Some another string")
String someOtherMethod();
}
问题是我的生成器使用:
for (JMethod method : targetClass.getMethods()) {
MyAnnotation descriptor = method.getAnnotation(MyAnnotation.class);
JParameter[] parameters = method.getParameters();
//some code
}
所以在 getInheritableMethods() 上更改 getMethods() 解决了这个问题。
抱歉没有详细说明,我不确定在这种情况下什么是重要的!