How to make the generic return type of a method dependend of the parameter type?
Posted
by deamon
on Stack Overflow
See other posts from Stack Overflow
or by deamon
Published on 2010-04-28T14:48:02Z
Indexed on
2010/04/28
14:53 UTC
Read the original article
Hit count: 185
I have a convert
method, which takes a String and a class as arguments and constructs an object of the given class, which will be returned.
The usage should look like this
Something s = Converter.convert("...", Something.class)
Is it possible to express this with Java generics?
Something like:
public static <T> T convert(String source, ??? TClass)
What would be ???
?
© Stack Overflow or respective owner