Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
Mixing self conscious parametrized types with inheritance
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Lew, post: 4194170"] "Unfriendly"? It's weaker to say "some subtype of Object" than "type Foo". It's not as strong an assertion. It's no unfriendlier than to say that 100 newtons is a weaker force than 1000. It's also not a proper solution because of your dodge on the declaration of 'Comparable' implementation. The cheating is that you implement 'Comparable<SC>' ionstead of 'Comparable<Base<SC>>'. The non-cheating way is to implement 'Comparable' of the class you want to compare, not the type parameter. Do you see that you Sorry, but that is just untrue. In there you have class BaseC<SC extends BaseC<?>> implements Comparable<SC> { I just now copied-and-pasted that line into this post, so I'm telling the truth. It shows how to handle it incorrectly because of the 'Comparable' dodge. Right, because it bumps up against the erasure issue. Except for implementing 'Comparable' on the type parameter instead of the class, which is not "exactly what should be done", it's "exactly what should not be done" because it makes for convoluted, hard-to-understand and not-exactly-what-you-want type assertions. The problem is that you aren't declaring 'class Foo implements You have found a workaround for the erasure issue. The problem is that you created a generics structure that doesn't declare exactly what you mean and is difficult to reason about. OTOH, the difficulty with the "normal" approach is that you cannot get Java generics to do what you want that way. Well, it requires that you cheat, in the sense that you have to warp the declaration of 'implements Comparable'. Notice I'm not saying one shouldn't do what you suggest, only that it requires some dodgy type assertions to get around erasure and playing loose with the semantics of 'implements Comparable'. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Mixing self conscious parametrized types with inheritance
Top