Difference between <?> and <L>

I'm making a listener system, and I was wondering what the difference between
public void register(Class<? extends Listener> listener)
public void register(Class<? extends Listener> listener)
and
public void register(Class<L extends listener> listener)
public void register(Class<L extends listener> listener)
Is either one better than the other, and if so, which?
30 Replies
JavaBot
JavaBot2y ago
This post has been reserved for your question.
Hey @cire! 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.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
cire
cireOP2y ago
Why not? lol
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Crain
Crain2y ago
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.
cire
cireOP2y ago
so the second doenst even compile Ok welp Ty
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Crain
Crain2y ago
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
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Crain
Crain2y ago
Oh, that sucks
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Crain
Crain2y ago
:shrugging: I avoid generic likes the plague
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Crain
Crain2y ago
People like to get too clever with them, causes problems.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Crain
Crain2y ago
Regardless, the best version of the function is public void register(Listener listener).
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
cire
cireOP2y ago
The issue here is that I also need this to work as an list
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
cire
cireOP2y ago
So i cant just use Listener<listener> as a list it wont work for my purposes
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Crain
Crain2y ago
myList.stream().map(other::register);
cire
cireOP2y ago
Why can't I use
List<Listener<?>>
List<Listener<?>>
ok
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Crain
Crain2y ago
Where List<? extends Listener>
cire
cireOP2y ago
he said u can't use it to fix
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
cire
cireOP2y ago
oh ok well ty
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBot2y ago
Post Closed
This post has been closed by <@853056773945819146>.
Want results from more Discord servers?
Add your server