#Get org.bukkit.entity.Player Array from the Player Collection
1 messages · Page 1 of 1 (latest)
Read what I mentioned
And ftr it’s a Collection<? extends Player>
important detail
I still don’t get what you wanted to do? Like converting the array type CraftPlayer[] to just Player[]?
The Idea was I could convert the Playerlist to the old format (Array) to allow for 1.8 compatibility. And Last I checked the old Version returned Player[]
That’s for like 1.7 and lower or smtng
early 1.8
Apparently it got changed during 1.8.3 Developement
No lol
But since ? still extends player, I shouldn't I be able to cast the subclass to the superclass?
Server::getOnlinePlayers has actually been returning the type Collection<out Player> even in 1.7
well as you mentioned yourself the type is erased
However at compile time Collection<? extends Player> means it could under the hood be a Collection<? extends CraftPlayer>
aaa Collection<? extends CraftPlayer> is a subtype of Collection<? extends Player>
anyways
Because CraftPlayer extends Player? bc Otherwise the returntype at runtime would be wrong wouldn't it?
If you just want a Collection<Player> or a Player[] do smtng like
getOnlinePlayers().stream().map(Player::getPlayer)
Then either
collect(Collectors.toList());
or
toArray(Player[]::new)
Yes
But generics is a bit special
aaa some types are erased at runtime and only lives at compile time, checking and converting might be unsafe