Difference between <?> and <L>
I'm making a listener system, and I was wondering what the difference between and
Is either one better than the other, and if so, which?
30 Replies
⌛
This post has been reserved for your question.
Hey @cire! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose 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.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Why not? lol
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
public void register(Class<? extends Listener> listener)
implies any class that extends Listener can work.
public void register(Class<L extends Listener> listener)
implies the class this resides in has <L extends Listener>
as a generic argument.so the second doenst even compile
Ok welp
Ty
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
It's also just better to use
public void register(Listener listener)
, since you don't care about anything but the fact it extends the class.Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Oh, that sucks
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
:shrugging: I avoid generic likes the plague
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
People like to get too clever with them, causes problems.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Regardless, the best version of the function is
public void register(Listener listener)
.Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
The issue here is that I also need this to work as an list
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
So i cant just use Listener<listener>
as a list
it wont work for my purposes
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
myList.stream().map(other::register);
Why can't I use
ok
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Where
List<? extends Listener>
he said u can't use it to fix
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
oh
ok well ty
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Post Closed
This post has been closed by <@853056773945819146>.