How does java get the method to be reflected
Editor to share with you how to get java to reflect the method, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Get the method to reflect
When you get a reflection method, there are two methods, getMethod and getDeclaredMethod.
Class Class {@ CallerSensitive public Method getMethod (String name, Class...) ParameterTypes) throws NoSuchMethodException, SecurityException {Objects.requireNonNull (name); SecurityManager sm = System.getSecurityManager (); if (sm! = null) {/ / 1. Check method permissions checkMemberAccess (sm, Member.PUBLIC, Reflection.getCallerClass (), true);} / / 2. Get method Method method = getMethod0 (name, parameterTypes); if (method = = null) {throw new NoSuchMethodException (methodToString (name, parameterTypes));} / / 3. Returns a copy of the method return getReflectionFactory () .copyMethod (method);} @ CallerSensitive public Method getDeclaredMethod (String name, Class...) ParameterTypes) throws NoSuchMethodException, SecurityException {Objects.requireNonNull (name); SecurityManager sm = System.getSecurityManager (); if (sm! = null) {/ / 1. The check method is permission checkMemberAccess (sm, Member.DECLARED, Reflection.getCallerClass (), true);} / / 2. Get method Method method = searchMethods (privateGetDeclaredMethods (false), name, parameterTypes); if (method = = null) {throw new NoSuchMethodException (methodToString (name, parameterTypes));} / / 3. Return a copy of the method return getReflectionFactory (). CopyMethod (method);}} above is all the content of the article "how to get the method to be reflected by java". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!