java - Getting a list of accessible methods for a given class via reflection -
Is there a way to get a list of methods of a given class (publicly not required) will be accessible ? The code in question will be in a completely different category.
Example:
Public category A {public zero method A1 (); Protected Zero Method A2 (); Zero method A3 (); Private Zero Method A4 (); } The expansion of the public square b is a {public zero method B1 (); Secure Zero Method B2 (); Private Zero Method B3 ();
I want to class b
:
- all your methods
-
MethodA1
andmethodA2
class bya
-
methodA3
if and only if classb
should not be included in the results ofa
methodA4
in the same package because it is not accessible to the class < Code> b . To clarify once more, the codes that need to find and return the above methods will be in a completely different category / package.
Now, Class.getMethods ()
gives only to public methods and thus will not do what I want to do; class.gateclair mode ()
returns the way for the existing class only. Although I can definitely use later and after checking the visibility rules manually, I can run the class hierarchy, but I do not want to have a better solution, I have forgotten something clearly here? Use to obtain a list of all methods (private or otherwise) from the class or interface.
class c = ob.getClass (); (Method method: c.getDeclaredMethods ()) {If (method.getAnnotation (PostConstruct.class)! = Null) {System.out.println (method.getName ()); }}
Note: This does not include inherited methods. Use it for it will return all public methods (inherited or not).
To make a detailed list of all the things that reach a class (including the inherited methods), you must cross the tree to expand the classes therefore:
class c = Ob.getClass (); (Class C = obGetClass (); c! = Faucet; C = C.GetSuperCLus () (for method method: C.GetchedClearard Maths ()) {if (method.Gotnotation (PostConstruct.class)! = Tap) {System.out.println (c.getName () + "." + Method.getName ()); }}}
Comments
Post a Comment