楼主的意思没表达清楚
instanseof 是不能判定的,可以调用该方法来测试
instanseof 是不能判定的,可以调用该方法来测试
解决方案 »
- 把一个字符串的首字母改成大写的最佳实现?
- 做一道题,但不知做错没有。
- 为什么编译时为出现"package aa does not exist"呢?哪位大哥能告诉我
- StringBuffer的capacity变化规律
- ********* Java 中关于建立 数据库 连接的问题 ********
- 简单的反射问题
- 急救!!!用java的Graphics绘图,如何改变线条粗细?
- 一个简单问题,关于字符串
- java socket 问题
- 动态生成一组radio,所用的方法不能判断哪个被选中!(静态生成的可以)
- 在程序运行时,能在某一小段时间内屏蔽掉对JMenu 和 JMenuItem的键盘快捷触发吗?
- 真是见鬼了,我自己的帖子怎么没法删除?
JDK中的说明:
public boolean isAssignableFrom(Class cls)
Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter. It returns true if so; otherwise it returns false. If this Class object represents a primitive type, this method returns true if the specified Class parameter is exactly this Class object; otherwise it returns false.
Specifically, this method tests whether the type represented by the specified Class parameter can be converted to the type represented by this Class object via an identity conversion or via a widening reference conversion. See The Java Language Specification, sections 5.1.1 and 5.1.4 , for details.Parameters:
cls - the Class object to be checked
Returns:
the boolean value indicating whether objects of the type cls can be assigned to objects of this class
Throws:
NullPointerException - if the specified Class parameter is null.
Since:
JDK1.1
那岂不是没法动态判定了,比如我想在程序中实现这个动作如果对象实现了燃油这个接口,那我就调用这个对象和燃油相关的方法,如果实现了电动这个接口,那我就调用和电动接口相关的方法应该还是 cbhyk 的方法可行吧。可能我的问题没问清,但还是谢谢大家了:)
}