A
A
Anton2019-02-05 12:04:48
Java
Anton, 2019-02-05 12:04:48

Why is ? used in generics, and is it equivalent to T/E?

I met such a design . I never thought about why I need it . Is the code above equivalent to this: . If so, why use . Function<? super T, ? extends U>
?
Function<E super T, E extends U>
?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
EVGENY T., 2019-02-05
@Anton238

Quoting approximately Eckel:
<?> - unlimited mask, means "anything", in most cases the compiler does not see the difference between T and <?>.
Without ? you can do more with parameters, but with ? - accept a wider range of parameters.

E
engineerVadim, 2019-02-05
@engineerVadim

? extends U - some type that is a descendant of U, ? super T - some type that is an ancestor of T. Your scheme (as you have written) is usually applied: the first part for the receiver, the second for the source when processing something.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question