In a previous Article blog post: http://www.cnblogs.com/guangshan/p/4660564.html
There are some places in the source code.
This.bridgedmethod = Bridgemethodresolver.findbridgedmethod (method);
So what is Bridgedmethod?
After finding out, this is called bridging method: http://freish.iteye.com/blog/1158008
The Java compiler uses the bridge approach to compatibility with non-generic usages where generics are supposed to be used.
The following code:
Public classTestbridgemethod { Public Static voidMain (string[] args) {p P=NewS (); P.test (NewObject ()); }}classP<t> { Publict Test (T t) {returnT; }}classSextendsP<string>{@Override Publicstring Test (String t) {returnT; }}
P refers to an object of S, but the return value of S's test method is a string, there is no generic in jdk1.4, and the P.test (new object) is not checked so that it is reported at the time of the call ClassCastException
When declaring p, using p<string> p will not have such a problem.
To be compatible with non-generic code, the Java compiler generates two methods for test. Look at the following code:
ImportJava.lang.reflect.Method;Importjava.util.Arrays; Public classTestbridgemethod { Public Static voidMain (string[] args) {Class<?> clazz = S.class; Method[] Methods=Clazz.getmethods (); for(Method method:methods) {System.out.println (Method.getname ()+ ":" + arrays.tostring (Method.getparametertypes ()) +Method.isbridge ()); } }}classP<t> { Publict Test (T t) {returnT; }}classSextendsP<string>{@Override Publicstring Test (String t) {returnT; }}
The result of the operation is:
Test:[class Java.lang.string]false
Test:[class Java.lang.object]true
Getclass:[]false
Hashcode:[]false
Equals:[class Java.lang.object]false
Tostring:[]false
Notify:[]false
Notifyall:[]false
Wait:[long, Int]false
Wait:[]false
Wait:[long]false
The compiler generates two test methods for S, one parameter is string, and is used for generics. One parameter is object, which is used for non-generics, and this method is the bridge method, which calls Method.isbridge to return true.
The previously mentioned failure to use generics correctly results in cross-type checking, which is caused by bridging methods.
There are also some useful collections of util tools in the spring source code:
Http://www.cnblogs.com/younggun/p/3247262.html
Additions to Java Reflection: bridging methods and some tool classes in spring