I have seen declarations, interfaces and classes that go TYPE<CLASS>
What does this do/mean?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Without evidence, I believe you’re talking about Java’s Generics support…
Before Java 5 it was difficult to provide classes that were capable of supporting multiple different types of Objects without having to code for each specific situation, so it was common for people to pass
Objectinstead.This leads to many difficult choices to make at runtime, you’d have to do a runtime check to see if it was possible to cast a given Object to a usable type…for example
Now, this is reasonably obvious, but if you were passed just a
List, you’d have to check each and every element in the list for correctness…But now, we can do this…
This is a contract that basically says “This list only contains Integer type’s of objects”.
With generics you can construct a single class that is capable of handling multiple different data types or a family of data types (ie constraint the parameter so that it must be extended from a particular parent type).
Basically says, this will contain objects that inherit from
Number, includeInteger,Long,Double,Float…Often in method and class decelerations you will see something similar to…
or
This allows you to refer to
Tas if it were a concrete object type, for example…This allows the compiler (and JVM) to essentially “replace” the marker
Twith a concert type (okay, it’s a little more complicated then that, but that’s the magic)…This allows to do things like…
And know that it will only ever accept the type of object I specify…
Have a read through the link in the first paragraph, I’m sure it can do more justice then I can 😉