如何通过反射来确定Java类是否是抽象的 [英] How can I determine whether a Java class is abstract by reflection

查看:161
本文介绍了如何通过反射来确定Java类是否是抽象的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过Jar文件中的类进行交互,并希望找到那些不抽象的。我可以通过实例化类和陷阱InstantiationException,但有一个性能命中,因为一些类有重大的启动来解决这个问题。我在Class.java文档中找不到任何明显的isAbstract()。

I am interating through classes in a Jar file and wish to find those which are not abstract. I can solve this by instantiating the classes and trapping InstantiationException but that has a performance hit as some classes have heavy startup. I can't find anything obviously like isAbstract() in the Class.java docs.

推荐答案

链接应该有帮助。

 Modifier.isAbstract( someClass.getModifiers() );

另外:

http://java.sun.com/javase/6/ docs / api / java / lang / reflect / Modifier.html

http://java.sun.com/javase/6/docs/api/java/lang/Class.html# getModifiers()

这篇关于如何通过反射来确定Java类是否是抽象的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆