Skip to content

Instantly share code, notes, and snippets.

@mrWinston
Last active October 21, 2015 15:10
Show Gist options
  • Save mrWinston/b9f9baa96c984a119bd4 to your computer and use it in GitHub Desktop.
Save mrWinston/b9f9baa96c984a119bd4 to your computer and use it in GitHub Desktop.
Java Private Method Invokation #java #private #reflection
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://www.wtfpl.net/ for more details.
*/
try {
Method m = Object.class.getDeclaredMethod("myPrivateMethod", String.class, Serializable[].class, MyParameterObject.class)
m.setAccessible(true);
m.invoke(new Object(),"myString", new Serializable[]{123, 44}, new MyParameterObject());
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment