This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "generics" Watch "generics" New topic
Author

generics

saravanan ragunathan
Ranch Hand

Joined: Aug 02, 2010
Posts: 84
the below code doesn't give errors


but this code generates Incomptible types error


what is the difference between the two ...i expected the same error for first code


"I Love Java Ranch"
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

What if T is replaced with Integer or String?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18509
    
  40

All objects inherits from the Object class type. The reverse is not true. The compiler would complain even if you used a specific type (and not generics) here.

[EDIT: Beaten to the answer again]

Henry


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

Joined: Aug 02, 2010
Posts: 84
thanks henry....i understand the concept

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: generics
 
Similar Threads
Doubt in Object class
aMethod (Integer ) is not defined
Passing subclass objects to overridden methods taking superclass args.
Probleme with generics
What Are the Rules about what Types can be Inferred with a generic Method?