Reflection is definitely not a beginner's subject, so I'll move the discussion to a more appropriate forum. Also, please note that ItDoesntWorkIsUseless. If you told us what you tried, and what exactly did or did not happen, we'd be in a much better position to help.
Each of their nuggets of wisdom contracted to a sound bite: Joshua Bloch: Write Lots of Code; Chet Haase: Don't Put Your Entire Application in One Method; Masood Mortazavi: Start Simple and Keep Learning; Cay Horstmann: First, Don't Panic
Joined: Jan 28, 2009
I wrote it's now... don't know if its works.
And if you want access and invoke the private Methods you only need add this line before "return m;"
Marky Vasconcellos wrote:I wrote it's now... don't know if its works.
That solution would work for all methods, not only public ones. There is one "but" though: getMethod and getDeclaredMethod never return null, but throw a NoSuchMethodException instead. So your code would be this:
Of course you can wrap the NoSuchFieldException in a RuntimeException if you don't want the checked exception:
Just be careful - your method only looks for methods without a parameter.
Now, as I've said before, if you only need to look for public methods, it's much simpler:
subject: java reflection to invoke parent class method