Am i understand the reason for introduction bridge method correctly?
I think yes. If compiler didn't generate the bridge method, then the method in the subclass would be an overloaded version of super class method, and not the overridden version. As you already seem to understand.
What is the necesseraly and enough conditions for bridge method creating?
When you extend or implement a parameterized type, and type erasure changes the signature of the method in the super class.
If we write
Object o= new Integer(5); setData(o);
thensetData(Object)
will called. It is not true.
I don't understand what do you mean by that. You should test this behaviour on non-generic code. When a method is overloaded, then a method call is binded to which method is decided at compile-time, based on the declared type of the parameter you pass. Since the declared type in this case is Object
, it will invoke setData(Object)
version.