(Class c, Object[] args)
| 302 | } |
| 303 | |
| 304 | public static Object invokeConstructor(Class c, Object[] args) { |
| 305 | try |
| 306 | { |
| 307 | Constructor[] allctors = c.getConstructors(); |
| 308 | ArrayList ctors = new ArrayList(); |
| 309 | for(int i = 0; i < allctors.length; i++) |
| 310 | { |
| 311 | Constructor ctor = allctors[i]; |
| 312 | if(ctor.getParameterTypes().length == args.length) |
| 313 | ctors.add(ctor); |
| 314 | } |
| 315 | if(ctors.isEmpty()) |
| 316 | { |
| 317 | throw new IllegalArgumentException("No matching ctor found" |
| 318 | + " for " + c); |
| 319 | } |
| 320 | else if(ctors.size() == 1) |
| 321 | { |
| 322 | Constructor ctor = (Constructor) ctors.get(0); |
| 323 | return ctor.newInstance(boxArgs(ctor.getParameterTypes(), args)); |
| 324 | } |
| 325 | else //overloaded w/same arity |
| 326 | { |
| 327 | for(Iterator iterator = ctors.iterator(); iterator.hasNext();) |
| 328 | { |
| 329 | Constructor ctor = (Constructor) iterator.next(); |
| 330 | Class[] params = ctor.getParameterTypes(); |
| 331 | if(isCongruent(params, args)) |
| 332 | { |
| 333 | Object[] boxedArgs = boxArgs(params, args); |
| 334 | return ctor.newInstance(boxedArgs); |
| 335 | } |
| 336 | } |
| 337 | throw new IllegalArgumentException("No matching ctor found" |
| 338 | + " for " + c); |
| 339 | } |
| 340 | } |
| 341 | catch(Exception e) |
| 342 | { |
| 343 | throw Util.sneakyThrow(getCauseOrElse(e)); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | public static Object invokeStaticMethodVariadic(String className, String methodName, Object... args) { |
| 348 | return invokeStaticMethod(className, methodName, args); |
no test coverage detected