Java怎么使用注解和反射简化编程-创新互联
这篇文章主要介绍Java怎么使用注解和反射简化编程,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

具体如下:
一 点睛
当调用大量方法,可以使用反射和注解简化编程。
二 代码
import java.lang.annotation.Annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.util.ArrayList;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@interface testAnnoation10 {
public String name() default "methodname";
public String unit() default "unit";
}
public class ch21_10 {
public static void main( String[] args ) throws Exception {
ch21_10 ch9 = new ch21_10();
Method method[] = ch9.getClass().getMethods();
for (Method method2 : method) {
Annotation annotation = method2.getAnnotation(testAnnoation10.class);
Class> ts[] = method2.getParameterTypes();
if (method2.getName().indexOf("getData") == -1) continue;
ArrayList三 运行
Tempreture is 20 AF
Electricity is 100 Ah
SOC is 10 %
以上是“Java怎么使用注解和反射简化编程”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联网站建设公司行业资讯频道!
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
当前名称:Java怎么使用注解和反射简化编程-创新互联
文章位置:http://www.jxjierui.cn/article/depjpp.html


咨询
建站咨询
