This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 19655
    
  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: 18542
    
  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

 
It is sorta covered in the JavaRanch Style Guide.
 
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?