P
P
parkito2016-11-30 00:56:16
Java
parkito, 2016-11-30 00:56:16

How to understand a strange generic?

Hello. Please explain what the following generic entry means

public static <I, O> List<O> map(Stream<I> stream, Function<I, O> mapper)

What does '<'I, O'>' mean and how is it used before List? What is the name of this phenomenon?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Anton Tikhomirov, 2016-11-30
@Acuna

The phenomenon is called data type. In this case, this function returns a hash table with key-value pairs: keys are "I", values ​​are "O". The weird thing here is that it's just a hash table, so you can access its element by calling its key of type I, rather than just by element number as in a normal array.

E
Eugene, 2016-11-30
@zolt85

is used to declare that a method is a generic method, the enumerated types will be used in the signature or in the body of the method.

D
davidnum95, 2016-11-30
@davidnum95

this means that the function takes as arguments a Stream of type I and a Function of type I and O, returns a List of type O

A
Alexey, 2016-12-01
@TheKnight

I think you should pay attention to Alexander Matorin's video about Generics in Java.
Tyts!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question