1

How I can return generic type from method? I wrote like this, but it dont work:

private static JsArray<T> convertListToJsArray(Collection<T> list)

I need to get Collection as parameter, and return parametrized JsArray.

WelcomeTo
  • 19,843
  • 53
  • 170
  • 286
  • 1
    possible duplicate - http://stackoverflow.com/questions/450807/java-generics-how-do-i-make-the-method-return-type-generic – scibuff Mar 07 '12 at 10:39

2 Answers2

3

You must specify the type parameter in front of the return type:

private static <T> JsArray<T> convertListToJsArray(Collection<T> list) {}
michael667
  • 3,241
  • 24
  • 32
3

You need to declare the T type. This should work (notice the extra <T> before your return type):

private static <T> JsArray<T> convertListToJsArray(Collection<T> list)
Guillaume Polet
  • 47,259
  • 4
  • 83
  • 117