How do I rewrite this:
<T> T callMethod(String methodName, Object[] parameters) throws ... {
...
return (T) SomeClass.class.getDeclaredMethod(methodName, parameterTypes).invoke(binding, parameters);
}
so it doesn't generate a warning
warning: [unchecked] unchecked cast
return (T) SomeClass.class.getDeclaredMethod(methodName, parameterTypes).invoke(binding, parameters);
required: T
found: Object
where T is a type-variable:
T extends Object declared in method <T>callMethod(String,Object[])
I mean the no-SupressWarnings solution.
I think you'll have to live with the @SuppressWarnings(...) approach since the invoke() method returns an Object. Remember that generics are erased at runtime, and reflection happens at runtime...
Cheers,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With