I just created a class like this: NameOfTheClass<Raeaeraear>. What does it means? And why can I put whatever random stuff I want?
I just created a class like this: NameOfTheClass<Raeaeraear> . What does it means? And
Share
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.
That is called Generics. Generics is used to “tell” a instance of an class what kind of type it is going to work with, take f.ex a List
Here the list is parameterized. If you take a look at the List-interface source code, it is declared like this which means the interface List is generic.
In your case the class NameOfTheClass would be implementet somewhat like this, Note: Generics can be applied to both a Class or an Interface.
This class could be used like this:
Note: Any use of the doSome()-method will require a parameter of type Atype, this will be handled by the Java-compiler. So if you try to call the method with some other type, an compile-error will rise.
More readings : http://docs.oracle.com/javase/tutorial/java/generics/why.html