Forums Register Login

generics java 1.5

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
thanks Henry
I am Arthur, King of the Britons. And this is a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 448 times.
Similar Threads
Usage of generics
generics
generics
Generics
Generics
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:38:54.