Hi,
I've been attempting to invoke a private method whose argument is a parameter and I can't quite seem to get it right.
Here's kind of how the code looks so far:
public class TestClass {
public TestClass(){
}
private void simpleMethod( Map<String, Integer> testMap) {
//code logic
}
}
Then I attempt to use this to invoke the private method:
//instance I would like to invoke simpleMethod on
TestClass testClassObject = new TestClass();
//Hashmap
Map <String, Integer> testMap = new HashMap <String, Integer>();
//method I want to invoke
Method simpleMethod = TestClass.class.getDeclaredMethod("simpleMethod", Map.class);
simpleMethod.setAccessible(true);
simpleMethod.invoke(testClassObject, testMap); //Throws an IllegalArgumentException
As you can see, it throws an IllegalArgumentException. I've attempted to cast the hashmap back to a map, but that didn't work.
What am I doing wrong?