I have some questions about bridge method creating. We can apply bridge technique for covariant overriding. Now consider example from the official help:
public class Node<T>{
private T data;
public Node(T data){ this.data=data;}
public void setData(T data){
System.out.println("Node.setData");
this.data=data;
}
}
public class MyNode extends Node<Integer>{
public MyNode(Integer data){ super(data); }
public void setData(Integer data){
System.out.println("MyNode.setData");
this.data=data;
}
}
Let bridge method doesnt creating. Hence at run time class MyNode
have two methods: setData(Integer)
and setData(Object)
where last is inheritated from Node
. When we are calling setData(new Inetegr(5))
will called setData(Integer)
. If we write Object o= new Integer(5); setData(o);
then setData(Object)
will called. It is not true. So two questions:
- Am i understand the reason for introduction bridge method correctly?
- What is the necesseraly and enough conditions for bridge method creating?