1.class对象的getclasses()方法获取的是该类中所有的公共的内部类,以及从父类,父接口继承来的内部类。getinterfaces()方法返回类继承的所有接口。
import javax.print.attribute.standard.PrinterInfo; interface HasBatteries{} interface Waterproof{} interface ShootsThings{} class Toy{ Toy(){} Toy(int i){} } class FancyToy extends Toy implements HasBatteries,Waterproof,ShootsThings{ public FancyToy() { // TODO 自动生成的构造函数存根 super(1); } } public class ToyTest { public static void main(String[] args){ Class class1=null; try{ class1=class1.forName("FancyToy"); }catch (ClassNotFoundException e) { // TODO: handle exception } printInfo(class1); Class[] faces=class1.getInterfaces(); for(int i=0;i<faces.length><p>2.Class对象的forName()使用时传递的类名classname参数是需要全名的,不能只加类名,比如包名.类名,java.lang.String。</p> <pre class="brush:php;toolbar:false">import javax.print.attribute.standard.PrinterInfo; interface HasBatteries{} interface Waterproof{} interface ShootsThings{} class Toy{ Toy(){} Toy(int i){} } class FancyToy extends Toy implements HasBatteries,Waterproof,ShootsThings{ public FancyToy() { // TODO 自动生成的构造函数存根 super(1); } } public class ToyTest { public static void main(String[] args){ Class class1=null; try{ class1=class1.forName("FancyToy"); }catch (ClassNotFoundException e) { // TODO: handle exception } printInfo(class1); Class[] faces=class1.getInterfaces(); for(int i=0;i<faces.length></faces.length>
以上就是Java怎么在运行期间鉴定数据类型的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号