Returns the Class object associated with the class or interface with the given string name. The Class object is determined by passing the given string name to the Class.forName() method, unless the given string name represents a primitive type, in which cas
(String type, ClassLoader loader)
| 261 | * @throws ClassNotFoundException Loading class failed |
| 262 | */ |
| 263 | public static Class<?> toClass(String type, ClassLoader loader) throws ClassNotFoundException { |
| 264 | |
| 265 | int i0 = type.indexOf('['); |
| 266 | int dims = 0; |
| 267 | if (i0 > 0) { |
| 268 | // This is an array. Count the dimensions |
| 269 | for (int i = 0; i < type.length(); i++) { |
| 270 | if (type.charAt(i) == '[') { |
| 271 | dims++; |
| 272 | } |
| 273 | } |
| 274 | type = type.substring(0, i0); |
| 275 | } |
| 276 | |
| 277 | Class<?> c = switch (type) { |
| 278 | case "boolean" -> boolean.class; |
| 279 | case "char" -> char.class; |
| 280 | case "byte" -> byte.class; |
| 281 | case "short" -> short.class; |
| 282 | case "int" -> int.class; |
| 283 | case "long" -> long.class; |
| 284 | case "float" -> float.class; |
| 285 | case "double" -> double.class; |
| 286 | case "void" -> void.class; |
| 287 | default -> loader.loadClass(type); |
| 288 | }; |
| 289 | |
| 290 | if (dims == 0) { |
| 291 | return c; |
| 292 | } |
| 293 | |
| 294 | if (dims == 1) { |
| 295 | return java.lang.reflect.Array.newInstance(c, 1).getClass(); |
| 296 | } |
| 297 | |
| 298 | // Array of more than i dimension |
| 299 | return java.lang.reflect.Array.newInstance(c, new int[dims]).getClass(); |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Produces a String representing a call to the EL interpreter. |
no test coverage detected