Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

collections and generics

 
sweety singh
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the differnce between collections and generics.. since their declaration is also same and both are type safe.. please explain me..
thanks...
 
Henry Wong
author
Marshal
Pie
Posts: 21000
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generics was a feature that was added to Java with version 5. Basically, generic programming allows the developer to use types-to-be-named-later in their code. The collections classes is one of the largest used libraries in core Java that were ported to use it.

Henry
 
sweety singh
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so is collections a type of generics..
 
Henry Wong
author
Marshal
Pie
Posts: 21000
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sweety singh:
so is collections a type of generics..


The collection classes are implemented using generics. There are many other classes, which are not collection classes, which are also implemented using generics.

The collection classes also use the instanceof operator in its implementation. Does that meant that collections is a type of instanceof?

Henry
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generics can be used without the use of collections. Collections can be used without the use of generics. They are independent of each other. However coupling collections with light generics is a good idea. It prevents runtime bombs where you added something that you did not want to in the collection
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic