Untitled
unknown
plain_text
2 years ago
820 B
2
Indexable
Never
import java.lang.reflect.Constructor; public class MyMatrixTypeFactory { public static <T extends MyMatrixType<T>> T generateMatrixType(int numerator, int denominator, Class<T> tClass) throws Exception { Class<?> cls = Class.forName(tClass.getName()); Class<?>[] partypes = new Class[2]; partypes[0] = Integer.TYPE; partypes[1] = Integer.TYPE; Constructor<?> ct = cls.getConstructor(partypes); Object arglist[] = new Object[2]; arglist[0] = numerator; arglist[1] = denominator; T retobj = (T) ct.newInstance(arglist); return retobj; } public static <T extends MyMatrixType<T>> T generateMatrixType(int value, Class<T> tClass) throws Exception { return MyMatrixTypeFactory.generateMatrixType(value,1,tClass); } }