KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
See the following example: interface I {} class A implements I {} class B implements I {} class Foo{ void f(A a) {} void f(B b) {} static public void main(String[]args ) { I[] elements = new I[] {new A(), new B(), new B(), new A()}; Foo o = new Foo(); for (I element:elements) o.f(element);//won't compile } } Why doesn't overloading methods support upcasting? If overloading was implemented at run time, it would provide much more flexibility. E.g, the Visitor Pattern would be simpler. Is there any technical reason that prevents Java from doing this?
Tags (comma-separated)
Save Edits
Cancel