Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures - Retired Exploring the Java Collection Framework Meet the JCF

Generics in Real World

Hey guys, I understand that using generics makes the code flexible. but can anyone give me an example of real world use of Generics. besides it helps avoid type casting issue.

2 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Shafeeq:

There are countless examples, but one that I like to use is that of a business doing invoices. If you have a type of Invoice you can then create a List<Invoice> to make sure that the list only has items of type Invoice in the list. If you just use ArrayList you increase the chances of having something other than an Invoice in your list.

Does that help at all?

Happy coding, Ken

thnks ken..

Thanks sir You have even answered another question I had in mind about JCF