I come across Java code like this:
public interface Foo<E> {}
public interface Bar<T> {}
public interface Zar<?> {}
What is the difference among all three of the above and what do they call this type of class or interface declarations in Java?
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.
Well there’s no difference between the first two – they’re just using different names for the type parameter (
EorT).The third isn’t a valid declaration –
?is used as a wildcard which is used when providing a type argument, e.g.List<?> foo = ...means thatfoorefers to a list of some type, but we don’t know what.All of this is generics, which is a pretty huge topic. You may wish to learn about it through the following resources, although there are more available of course: