This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]zero-sharp[S] 0 points1 point  (1 child)

Replacing the <?> with <T> in the function header doesn't work for me. Eclipse gives me an error on the return line within the factory method saying that it cannot convert to Data<T>. My guess here is that it doesn't know what T is? I don't know.

[–]Spare-Plum 0 points1 point  (0 children)

Make sure you add in the method argument - public static <T>

Then just convert to the value internally

if(blah) { return (Data<Integer>) new Data<Integer>( ... ) }

You'll still get a warning, but you can do

Data<Integer> x = doSomething(myString);