Get the App
SLTechnology News&Howtos  ›  Development  › 

How does java get the method to be reflected

Shulou Source: shulou.com Published: 2022-06-01 04:38:29 10月16日 Update

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!

Tags: Method reflection article content copy permission check not much two most more knowledge industry information channel channel reference learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Xiaomi Apple Microsoft OPPO Reno