Last active
October 21, 2015 15:10
-
-
Save mrWinston/b9f9baa96c984a119bd4 to your computer and use it in GitHub Desktop.
Java Private Method Invokation #java #private #reflection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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