Biniman Idugboe wrote:
So, is super a hidden member of every subclass?
Biniman Idugboe wrote:Actually, I do not know what you meant by saying that one instance has multiple types.
Look at a class like this one. At the top of its documentation, it tells you that it is a subclass of Object, so it is an Object. It is also an instance of each of the interfaces it implements, so it is a Serializable, a Comparable, etc.
Biniman Idugboe wrote:. . . one instance has multiple types.
Biniman Idugboe wrote:Is ? super T a single parameter?
Winston Gutkowski wrote:I think they did a pretty good job in the circumstances, but lots of constructs (like Campbell's example above) just look "messy" - even after ... what is it now? ... 10 years?
Campbell Ritchie wrote:<T extends Comparable<T>> mightn't work; you don't know whether T itself implements Comparable<T> or whether one of its supertypes does.
This means that if you have a List<Orange>, the comparator that you pass to the sort method must be a Comparator<something that is a supertype of Orange>. For instance, you could pass a Comparator<Fruit>. Here, Fruit is a type argument passed to the type parameter T of Comparator.
Stephan van Hulst wrote:List.sort() accepts a Comparator<? super T> and not a Comparator<T>, because if it just so happens that I have a Comparator<Fruit> which sorts fruits by sweetness and I have a List<Strawberry>, then why shouldn't I be allowed to sort the strawberries with the comparator I already have?
Winston Gutkowski wrote:To me, the "? super" business is confusing nonsense, and furthermore mechanical nonsense. The first thing you learn about supertypes and interfaces is that they are inherited by ALL subtypes
I love Java, but it sounds like generics syntax is a mechanical issue, and maybe C# got it right (or 'righter').
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton