This is my sample code where i am getting the warning.
Class aClass = Class.forName(impl);
Method method = aClass.getMethod(\"getInstance\", null);
item = (Prefe
Well, the compiler warning tells you everything you need to know. It doesn't know whether to treat null
as a Class<?>[]
to pass directly into getMethod
, or as a single null
entry in a new Class<?>[]
array. I suspect you want the former behaviour, so cast the null
to Class<?>[]
:
Method method = aClass.getMethod("getInstance", (Class<?>[]) null);
If you wanted it to create a Class<?>[]
with a single null element, you'd cast it to Class<?>
:
Method method = aClass.getMethod("getInstance", (Class<?>) null);
Alternatively you could remove the argument altogether, and let the compiler build an empty array:
Method method = aClass.getMethod("getInstance");