gpt4 book ai didi

java - class.getAnnotation 和 getAnnotations 不能正常工作

转载 作者:搜寻专家 更新时间:2023-10-31 20:27:34 25 4
gpt4 key购买 nike

像这样从 gwt 类 SecureDispatchService:

@RemoteServiceRelativePath("dispatch")
public interface SecureDispatchService extends RemoteService {
Result execute( String sessionId, Action<?> action ) throws DispatchException;
}

RemoteServiceRelativePath:

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface RemoteServiceRelativePath {
/**
* The relative path for the {@link RemoteService} implementation.
*
* @return relative path for the {@link RemoteService} implementation
*/
String value();
}

测试代码很简单:

package com.name.sbts.wbts.sm;

import net.customware.gwt.dispatch.client.secure.SecureDispatchService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

public class TestClass {

public static void main(String[] args) {

Class c = SecureDispatchService.class;
System.out.println(c.getAnnotation(RemoteServiceRelativePath.class));
System.out.println(c.getAnnotations().length);
}
}

但是结果并不想要:

null
0

我在 eclipse 中使用 JRE1.7 运行这段代码

SecureDispatchService 在这个来自 google 的 jar 中:

gwt-dispatch-1.2.0.jar

我使用mvn eclipse:eclipse 来生成项目。这个jar文件作为eclipse项目的引用库,它的真实路径在我的.m2/repostory中。

最佳答案

发生这种情况是因为 gwt-dispatch 项目是使用旧的 gwt-user 依赖项(gwt 版本 2.0.4)编译的。在这个版本的 gwt 中,RemoteServiceRelativePath注释没有 @Retention(RetentionPolicy.RUNTIME)在其上,因此 RemoteServiceRelativePath 注释在运行时不可用。

关于java - class.getAnnotation 和 getAnnotations 不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29510159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com