#Generics question

9 messages · Page 1 of 1 (latest)

split steppe
#

What is the difference between doing
List<String> list = new ArrayList<>();
and
List<String> list = new ArrayList<String>();

rich geyserBOT
#

This post has been reserved for your question.

Hey @split steppe! 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.

zenith storm
#

no difference

#

it's just that the compiler can infer the generic arguments based on the type you've declared, so it's not needed to repeat it

#

just like you can do

var list = new ArrayList<String>();

and the compiler still knows that list is of type ArrayList<String>

split steppe
#

ah, understood

#

thank you

rich geyserBOT
# split steppe thank you

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.