• Post Reply Bookmark Topic Watch Topic
  • New Topic

generics java 1.5  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java 1.5 they added the ability to type Collections.

The syntax might be ArrayList<String> and now the ArrayList will only accept Strings - thus eliminating the need to cast Object back to the specific type.

It seems to me that an Object is pretty generic, so why is coding the specific type called a generic?

I suppose it doesn't matter what they call this new feature, unless there is something I don't understand about it - in which case it might be interesting to know why this feature is called generics.

Does anyone know why it's called generics?
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java didn't invent the term "generics". It is a common idea that is available with many languages.

The idea is that you can declare a class myclass<E>, which E will be determined later. It is "generic" because the code is written in such a fashion using E as if it is already defined.

You are build a generic class whose definition will be defined later.

Henry
 
dave Lande
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Henry
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!