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

一段值得余味的代码

2012-08-25 
一段值得回味的代码这个代码应该是每一个开源框架的ClassUtils都有的吧!本人觉得这段代码和经典,但又说不

一段值得回味的代码

这个代码应该是每一个开源框架的ClassUtils都有的吧!本人觉得这段代码和经典,但又说不出哪里好,只可意会,不可言谈。

?

public class ClassUtils{/** * Map with primitive wrapper type as key and corresponding primitive * type as value, for example: Integer.class -> int.class. */private static final Map primitiveWrapperTypeMap = new HashMap(8);/** * Map with primitive type name as key and corresponding primitive * type as value, for example: "int" -> "int.class". */private static final Map primitiveTypeNameMap = new HashMap(16);static {primitiveWrapperTypeMap.put(Boolean.class, boolean.class);primitiveWrapperTypeMap.put(Byte.class, byte.class);primitiveWrapperTypeMap.put(Character.class, char.class);primitiveWrapperTypeMap.put(Double.class, double.class);primitiveWrapperTypeMap.put(Float.class, float.class);primitiveWrapperTypeMap.put(Integer.class, int.class);primitiveWrapperTypeMap.put(Long.class, long.class);primitiveWrapperTypeMap.put(Short.class, short.class);Set primitiveTypeNames = new HashSet(16);primitiveTypeNames.addAll(primitiveWrapperTypeMap.values());primitiveTypeNames.addAll(Arrays.asList(new Class[] {boolean[].class, byte[].class, char[].class, double[].class,float[].class, int[].class, long[].class, short[].class}));for (Iterator it = primitiveTypeNames.iterator(); it.hasNext();) {Class primitiveClass = (Class) it.next();primitiveTypeNameMap.put(primitiveClass.getName(), primitiveClass);}}}
?

热点排行