Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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: 20080
    
  30

What if T is replaced with Integer or String?


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

Joined: Sep 28, 2004
Posts: 20057
    
  44

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: generics
 
jQuery in Action, 3rd edition