您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Java怎么在运行期间鉴定数据类型

2024/3/26 11:39:18发布26次查看
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
2.class对象的forname()使用时传递的类名classname参数是需要全名的,不能只加类名,比如包名.类名,java.lang.string。
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
以上就是java怎么在运行期间鉴定数据类型的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product