How to use getMethod () with primitive types?

This is the class:

class Foo { public void bar(int a, Object b) { } } 

Now I'm trying to "flip" this method from the class:

 Class c = Foo.class; Class[] types = { ... }; // what should be here? Method m = c.getMethod("bar", types); 
+55
java reflection
Feb 17 '11 at 18:12
source share
1 answer

Only int.class .

 Class[] types = { int.class, Object.class }; 

An alternative is Integer.TYPE .

 Class[] types = { Integer.TYPE, Object.class }; 

The same applies to other primitives.

+79
Feb 17 '11 at 18:14
source share



All Articles