mercredi 5 août 2015

Cannot understand reason for compiler warning

I'm using Java reflection in my code and I could see couple of warning notification as below:

Source code:

Class<?> c = Class.forName("complete.package.name.RegressionBuild");
RegressionBuild regression = (RegressionBuild) c.newInstance();
String methodName="debitCardDetails";
Method runtimeMethod = RegressionBuild.class.getDeclaredMethod(methodName, null);

Error:

The argument of type null should explicitly be cast to Class[] for the invocation of the varargs method getDeclaredMethod(String, Class...) from type Class. It could alternatively be cast to Class for a varargs invocation

Can somebody tell me the reason for this warning and how can i resolve it?

Also the following line throws these warning messages:

Source code:

String exeMethod = (String) runtimeMethod.invoke(regression, null);

Error:

The value of the local variable exeMethod is not used

The argument of type null should explicitly be cast to Object[] for the invocation of the varargs method invoke(Object, Object...) from type Method. It could alternatively be cast to Object for a varargs invocation

However, It returns proper method, also printed null value in output console.

Can somebody assist me to solve this issue.

Aucun commentaire:

Enregistrer un commentaire