Loads a class by name, supporting primitive types and array notation. @param name the class name to load @return the Class object, or null if the name is empty @throws ClassNotFoundException if the class cannot be found
(String name)
| 61 | * @throws ClassNotFoundException if the class cannot be found |
| 62 | */ |
| 63 | public static Class<?> forName(String name) throws ClassNotFoundException { |
| 64 | if (null == name || name.isEmpty()) { |
| 65 | return null; |
| 66 | } |
| 67 | Class<?> c = forNamePrimitive(name); |
| 68 | if (c == null) { |
| 69 | if (name.endsWith("[]")) { |
| 70 | String nc = name.substring(0, name.length() - 2); |
| 71 | c = Class.forName(nc, true, Thread.currentThread().getContextClassLoader()); |
| 72 | c = Array.newInstance(c, 0).getClass(); |
| 73 | } else { |
| 74 | c = Class.forName(name, true, Thread.currentThread().getContextClassLoader()); |
| 75 | } |
| 76 | } |
| 77 | return c; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Looks up a primitive class by name. |