Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Polymorphic Reference & Interfaces

 
Nasir Munir
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody explain
a)how polymorphic references seem to relax the type compatibility rules regarding assignment.
b)how can a class implement two intefaces each containing the same method signature.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi nasir
i know about the 2nd question. ans is - its a problem
when u implement two interfaces with same method in a class there is no compile time error or run time error but logically its not proper. which method u actually wanted to implement is not clear. also, u can't have two method implementation for two different interfaces in this case as the method name is same. so basically u r stuck but i guess u don't run into this kind of circumstances most of the time (may be 99% of the time)
i didn't understand the 1st question.
regards
maulin
 
Nasir Munir
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help
 
nate saider
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like we are taking the same class.... since I have similar issues.
I believe dual dispatch or multimethods come in handy in for your first question, but your question is vague.
I don't think you can have one class hierarchy implementing 2 interfaces with the same method name. BUT you can have two interfaces handling methods of the same name in separate class hierarchy.
The obvious guess from my basic knowledge of Java is that each interface has two different sets of derived subclasses inheriting these methods.
(i.e method gumbo()from interface A is being used by subclasses A, and method gumbo() of interface B is being used by subclasses B [the names A & B I used don't matter... I was just using them to point a relation between subclasses and each interface])
Maybe that is too obvious an answer... but I can't imagine why anyone would have 2 interfaces with the same method name in the same class hierarchy.
[ July 09, 2002: Message edited by: nate saider ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the following:

[ July 09, 2002: Message edited by: Ilja Preuss ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic