Skip to main content
gamedev.net
🔒 Locked

[java] Comparable interface

Started by bilsa 1 reply 650+ views
Original Post
bilsa
bilsa
Hi again, I have stumbled upon an issue iäve never really thought much about. I'm having a class structure like this: class A implements Comparable { } class C extends A implements Comparable { } Which apparently is not allowed :( Currently I need to use the old non generic Comparable interface, which forces me to use the "instanceof" operator. Is there any other sollution to my problem?
haegarr
haegarr
To clarify my previous post, notice please that Java doesn't dispatch overloaded function calls from runtime types! I.e. it doesn't look at runtime whether an instance is of type A or else C, and hence invokes the one or the other method. Instead, it invokes the best match considering the type known at compile time. Hence, although if you have both C.compareTo(A) and C.compareTo(C) implemented, you cannot be sure that C.compareTo(A) is never invoked with an instance of C (although you can be sure that C.compareTo(C) is never invoked with an instance of A, of course).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.