我想写一个方法来判断java类privatebooleanCheckEtype(Stringtype)throwsException{//传入的参数是String的,比如说Stringtype=java.lang.String;或者Stringtype=int;//怎么把这些参数...
我想写一个方法来判断java类
private boolean CheckEtype(String type) throws Exception
{ //传入的参数是String 的,比如说String type=java.lang.String;或者String type=int;
//怎么把这些参数转成Class ?
//我用Class clazz = ClassUtil.class.getClassLoader().loadClass(type);能把java.lang.String从String转成Class,但是int就不行,有什么比较好的方法吗?
//判断类的话,isPrimitive()只能判断int,short,这些,怎么判断java.lang.String呢?
}
求大神指点!!!
private boolean CheckEtype(String type) throws Exception
{ if(type=="int"){return(true);}
if(type=="double"){return(true);}
if(type=="float"){return(true);}
if(type=="long"){return(true);}
if(type=="short"){return(true);}
if(type=="boolean"){return(true);}
if(type=="byte"){return(true);}
if(type=="char"){return(true);}
if(type=="void"){return(true);}
else{
Class clazz = ClassUtil.class.getClassLoader().loadClass(type);
//基本型都判断好了,那么剩下的java.lang.String这种怎么判断呢
}
}
展开