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
  • 18,613
  • 51
  • 157
  • 276
  • 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,216
  • 22
  • 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
  • 46,469
  • 4
  • 81
  • 115