Here you can find the source of newInstance(Constructor> c, List
Parameter | Description |
---|---|
c | constructor to use |
parameters | constructor parameters |
@SuppressWarnings("unchecked") private static <T> T newInstance(Constructor<?> c, List<Object> parameters)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.List; public class Main { /**/* w ww . j a va2 s . c om*/ * * @param c * constructor to use * @param parameters * constructor parameters * @return */ @SuppressWarnings("unchecked") private static <T> T newInstance(Constructor<?> c, List<Object> parameters) { try { return (T) c.newInstance(parameters.toArray()); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } } }