aspose file tools
The moose likes Java in General and the fly likes Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Generics" Watch "Generics" New topic
Author

Generics

Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
So, what kind of coverage is given to generics in this book? Are they similar to C++ templates?

thanks,


Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26218
    
  66

I'm not Brett,but ...

Chapter 2 (20 pages) is all about generics. After that the authors use generics in their examples on other topics. So generics gets excellent coverage.

Generics are similar in concept to C++ templates except that you don't need a separate one for each type. For example, List<Integer> and List<String> aren't compiled into two classes the way they are in C++.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Brett McLaughlin
author
Ranch Hand

Joined: Sep 01, 2004
Posts: 30
Generics get pretty prominent coverage in the Tiger notebook. Although there is technically only a chapter on the subject (Chapter 2), there are a number of chapters that play a part -- for example, varargs have a lot to do with generics, and they get a chapter as well (Chapter 5).

In a nutshell, generics are more about type-safety and parameterization than they are templates, although the end-result is very similar. So you can, as the previous poster pointed out, do something like:

List<String> stringList = new LinkedList<String>;

That means that, at compile time, javac ensures that only Strings are added to stringList. However, at runtime, you can get around these things because of erasure (I just posted some things on that here: http://www.coderanch.com/t/374888/java/java/Reflection-jdk)

Let me know what you want to drill into -- I'm trying to do overview answers, and let the folks on the forum direct more specific discussion.

Thanks
Brett


Series Editor, Head First<br />Author of <a href="http://www.amazon.com/exec/obidos/ASIN/0596102259/newinstance-20" target="_blank" rel="nofollow">Head Rush Ajax</a> and <a href="http://www.amazon.com/Head-First-Object-Oriented-Analysis-Design/dp/0596008678/ref=pd_bbs_sr_1/104-5348268-5670331?ie=UTF8&s=books&qid=1192568453&sr=8-1/newInstance-20" target="_blank" rel="nofollow">Head First OOA&D</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generics
 
Similar Threads
Generics
Generics
Generics
Generics
Generics