Why do I have to explicitly cast sometimes for varargs?
- by Daniel Lew
I've got a Class that uses reflection a lot, so I wrote a method to help out:
private <T> T callMethod(String methodName, Class[] parameterTypes, Object[] args) {
try {
Class c = mVar.getClass();
Method m = c.getMethod(methodName, (Class[]) parameterTypes);
return (T) m.invoke(mVar, args);
}
// Insert…