#Generics naming confusion

21 messages · Page 1 of 1 (latest)

crimson grotto
#

Hello,

why is

public static <T> List<T> asList(T[] array)

correct, and not

public static List<T> asList(T[] array)

?

mental mantleBOT
#

This post has been reserved for your question.

Hey @crimson grotto! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

tiny tusk
#

because T is not defined in the second example

crimson grotto
#

So you ALWAYS have to declare BEFORE the return value what generic types exist?

tiny tusk
#

If its a static method, or the method needs its own generics you have to declare it before the return value. If the method is not static and doesn't need its own generics but can use the generic type of the class you don't need to declare any additional generics.

tiny tusk
crimson grotto
crimson grotto
tiny tusk
#

yeah all static methods have to define their own generics

crimson grotto
#

I just did not know you have to define the generic at one point (or whatever you call the T here)

tiny tusk
#

well if you don't define the generic java has no idea what you are talking about xD

crimson grotto
#

Thats....true

#

I am so overworked by the tasks this week I get everything wrong I possibly can : D

#

Thanks (once again this week :D)!

mental mantleBOT
# crimson grotto Thanks (once again this week :D)!

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

tiny tusk
crimson grotto
tiny tusk
#

oh shit i forgot

crimson grotto
#

The IDE thing

tiny tusk
#

oh yeah. Well if you have questions feel free to send them here 🙂