How to realize bridging by reflection in Java
This article shows you how to use reflection to achieve bridging in Java, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
/ * add the Method array to uniqueMethods * @ param uniqueMethods * @ param methods * / private void addUniqueMethods (Map uniqueMethods, Method [] methods) {for (Method currentMethod: methods) {/ / ignore the bridge method if (! currentMethod.isBridge ()) {/ / get the method signature String signature = getSignature (currentMethod) / / check to see if the method is already known / / if it is known, then an extended class must have / / overridden a method / / uniqueMethods does not contain this method signature, add if (! uniqueMethods.containsKey (signature)) {/ / add uniqueMethods.put (signature, currentMethod);}
In order to avoid interference to friends who have not seen this source code, I added some comments to the code. Here, I would like to thank the source code boss of Taro Road. Luo this werewolf is really strong. I recommend you to pay attention to it. Read the source code together and go bald together.
Back to the point, I wonder what the isBridge of currentMethod.isBridge () is for, so open it and have a look.
Public boolean isBridge () {return (getModifiers () & Modifier.BRIDGE)! = 0;} @ Overridepublic int getModifiers () {return modifiers;} the above is how to bridge with reflection in Java. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.