7

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?

1 Answer 1

12

Try this:

Class[] parameterTypes = new Class[] {byte[].class};
Sign up to request clarification or add additional context in comments.

4 Comments

great, thanks, that worked. I don't really understand why Integer[] x = {5}; and Integer[] y = {new Integer(5)}; work.
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.
(And that should probably be Class<?>[].
Integer[] x = {5} works because 5 is autoboxed -- equivalent to Integer.valueOf(5).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.