I am new to JAVA generics below the return type is void but why are they giving the type .
public static <U> void addBox(U u,List<Box<U>> boxes){
Box<U> box = new Box<U>();
box.setT(u);
boxes.add(box);
}
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.
The
<U>isn’t a return type. It is declaring thatUis a generic class that will be used in the method’s parameters and in the method body.You can read more about generic methods and their syntax here.