aspose file tools*
The moose likes Beginning Java and the fly likes Generic method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Generic method" Watch "Generic method" New topic
Author

Generic method

Vivian Josh
Ranch Hand

Joined: Oct 31, 2006
Posts: 112
Can someone explain me following code and why can't we have B as one of the answer ?



The author has given A, E and F as correct answers. I am bit confused about B. If we can accept <?> then why not <Object> ?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19004
    
  40

Vivian,

Please Quote Your Sources.

Thanks,
Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
A Set<Orange> or a Set<Citrus> is not the same as a Set<Object>.
joko mujoko
Greenhorn

Joined: Dec 28, 2006
Posts: 8
That's why we need to declare Set as a set of particular instance a class. Set<Object> is just like Set in Java 1.4.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
To explain more about what Keith Lynn said. The fact that Citrus extends Object and Orange extends Citrus does not imply that a List<Orange> is a subclass of List<Citrus> or List<Orange>.

Go through the Generics part of the Java Tutorial, which explains why.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generic method