This discussion is archived
5 Replies Latest reply: Jul 6, 2010 5:37 AM by EJP RSS

Passing null value to Method.invoke

843798 Newbie
Currently Being Moderated
Trying to invoke a class method setter with the null value gets complicated when using reflection. How does one go about passing null to a method, when invoke() expects null to represent an argument list of length zero?

Static code:
Thingy t = new Thingy();

Reflection equivalent:
Thingy t = new Thingy();
Method nameSetter = t.getClass().getMethod("setName", String.class);
nameSetter.invoke(t, ????????);