aspose file tools*
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
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: 19759
    
  20

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: 18977
    
  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