views:

307

answers:

1

I'm trying to use reflection to call a method that takes in a byte array.

I'm starting off doing:

Class myClass = anObject.getClass();
Class[] parameterTypes =
 {byte[].getClass();};

But that doesn't work (class expected, } expected) on the byte[] line. Anyone know what I should do? Cast to an Object and declare that the method takes an Object?

+4  A: 
Class[] parameterTypes = new Class[] {byte[].class};
ChssPly76
great, thanks, that worked. I don't really understand why Integer[] x = {5}; and Integer[] y = {new Integer(5)}; work.
jbu
Well, `Class[] parameterTypes = {byte[].class}` works too, as do your examples. The problem with your original code is trying to invoke getClass() _instance_ method on byte[] declaration.
ChssPly76
(And that should probably be `Class<?>[]`.
Tom Hawtin - tackline
ooooooooohh....
jbu
`Integer[] x = {5}` works because `5` is autoboxed -- equivalent to `Integer.valueOf(5)`.
David Moles