判断变量类型

 1 public class ClassType {
 2     public static void main(String[] args) {
 3         Integer i=0;
 4         String type = ifClassType(i);
 5         System.out.println(type);
 6     }
 7     
 8     public static String ifClassType(Object obj) {
 9         String type="";
10         if(obj instanceof Integer){
11             type = "Integer";
12         }else if(obj instanceof Short){
13             type = "Short";
14         }else if(obj instanceof Double){
15             type = "Double";
16         }else if(obj instanceof Long){
17             type = "Long";
18         }else if(obj instanceof String){
19             type = "String";
20         }else if(obj instanceof Boolean){
21             type = "Boolean";
22         }else if(obj instanceof Character){
23             type = "Character";
24         }else if(obj instanceof T){//自定义类型
25             type = "T";
26         }
27         return type;
28     }
29     class T{}
30 }

 

转载于:https://www.cnblogs.com/luoyanli/p/3210290.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值