首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Java变量门类识别的3种方式

2013-03-17 
Java变量类型识别的3种方式package com.cxyapi.ooimport java.util.HashMapimport java.util.Map/** 类

Java变量类型识别的3种方式
package com.cxyapi.oo; import java.util.HashMap; import java.util.Map; /** 类型识别工具 * @author cxy @ www.cxyapi.com */ public class TypeTools { //获得类型 public static Map<String,String> getType(Object o) { Map<String,String> typeInfo=new HashMap<String,String>(); typeInfo.put("类型", o.getClass().getSimpleName()); typeInfo.put("描述", "引用类型"); return typeInfo; } public static Map<String,String> getType(int i) { Map<String,String> typeInfo=new HashMap<String,String>(); typeInfo.put("类型", "int"); typeInfo.put("描述", "整形"); return typeInfo; } public static Map<String,String> getType(long l) { Map<String,String> typeInfo=new HashMap<String,String>(); typeInfo.put("类型", "long"); typeInfo.put("描述", "长整型"); return typeInfo; } public static Map<String,String> getType(boolean b) { Map<String,String> typeInfo=new HashMap<String,String>(); typeInfo.put("类型", "boolean"); typeInfo.put("描述", "布尔类型"); return typeInfo; } public static Map<String,String> getType(char b) { Map<String,String> typeInfo=new HashMap<String,String>(); typeInfo.put("类型", "char"); typeInfo.put("描述", "字符"); return typeInfo; } public static Map<String,String> getType(float f) { Map<String,String> typeInfo=new HashMap<String,String>(); typeInfo.put("类型", "float"); typeInfo.put("描述", "单精度浮点型"); return typeInfo; } public static Map<String,String> getType(double d) { Map<String,String> typeInfo=new HashMap<String,String>(); typeInfo.put("类型", "double"); typeInfo.put("描述", "双精度浮点型"); return typeInfo; } public static Map<String,String> getType(String s) { Map<String,String> typeInfo=new HashMap<String,String>(); typeInfo.put("类型", "String"); typeInfo.put("描述", "字符串类型"); return typeInfo; } }

?

热点排行