java 判断自定义类型_判断一个类型是java本身的类型还是自定义的类?

我想写一个方法来判断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这种怎么判断呢

}

}

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值