File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes is a class both subclass and superclass to itself? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "is a class both subclass and superclass to itself?" Watch "is a class both subclass and superclass to itself?" New topic
Author

is a class both subclass and superclass to itself?

ravi satti
Greenhorn

Joined: Oct 16, 2007
Posts: 13
when we can say something like
List<? extends Number> myList1 = new ArrayList<Number>();
does it mean 'a class is subclass to itself'?

when we can say something like
List<? super Number> myList2 = new ArrayList<Number>();
does it mean 'a class is superclass to itself'?
Xyz Abc
Greenhorn

Joined: Aug 24, 2007
Posts: 27
when we can say something like
List<? extends Number> myList1 = new ArrayList<Number>();
does it mean 'a class is subclass to itself'?


It means that any class which extends Number can be considered.

when we can say something like
List<? super Number> myList2 = new ArrayList<Number>();
does it mean 'a class is superclass to itself'?


No, it doesn't mean a class is a superclass to itself, it means any class which is a superclass of Number, that the list can be of that "type".

Guys please correct me if I'm wrong!
[ December 01, 2007: Message edited by: Xyz Abc ]
Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
I believe the standard Java terminology does not in fact describe a class as a subclass or superclass of itself. For instance, we usually say that Object has no superclass, or that private members are not visible to subclasses.

However, you're right that the Generics wildcard syntax does seem to be inconsistent with this usage. The way I like to think of it is that the keywords "extends" and "super" are being used in a completely different way here, much like how the "final" keyword has very different semantics when applied to methods and instance variables. Thus, when used in the context of Generics wildcards, "extends" and "super" are more like "subset" and "superset" in mathematics, rather than "subclass" and "superclass". (As you probably know, in mathematics a set A is both a subset and superset of itself.)
[ October 20, 2007: Message edited by: Kelvin Lim ]

SCJP 5.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is a class both subclass and superclass to itself?
 
Similar Threads
Generic Question: wildcard with super
generic gotcha's
Question on Collection class of Java 5
S&B 1.5 Chapter 7, question 16
Question on Generics