jbu
jbu

Reputation: 16131

Java: proper way to get the class of a primitive array for reflection

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?

Upvotes: 7

Views: 11057

Answers (1)

ChssPly76
ChssPly76

Reputation: 100706

Try this:

Class[] parameterTypes = new Class[] {byte[].class};

Upvotes: 12

Related Questions