O
O
Olehor2018-03-07 12:51:40
Java
Olehor, 2018-03-07 12:51:40

Why Generic in front of return type (Java)?

Why Generic in front of return type? what is the purpose of Generic before void
public <T> String method() {...}
public <T> void method() {...}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2018-03-07
@zagayevskiy

In the example - there is no point, this generic can simply be removed. It makes sense in a situation where the method signature must be generic. for examplepublic <T> String method(T t) {...}

S
Sergey Gornostaev, 2018-03-07
@sergey-gornostaev

This is the syntax for declaring methods that work with generic parameters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question