What would be the best way to check in an object being passed into a method extended a given class?
Currently i have a method that takes a ByteBuffer of data to send and a 'player' class that i wrote, and queues the data up on the IO server to be sent to the client:
public void send(ButeBuffer toSend, Player player)
{
// prep the byte buffer for sending, and queue it on the IO server
}
What i would like to be able to do is let the player object passed in be any object that extends the player class. I have done some searches and found something like this:
public void send(ByteBuffer toSend, Player<? extends Player> player)
{
// prep the byte buffer for sending, and queue it on the IO server
}
But that is giving me compile errors, and i don't understand exactly whats going on. Would this be the proper way to do this? And if so, could anyone explain what this code is specifically doing and why it isn't working and or link me to an article that explains this in greater detail.
Alternatlly, I suppose i could set it up something like this:
public void send(ByteBuffer toSend, Object player)
{
// Check that the player extends Player, using instanceof or something
// along those lines
// Prep the ByteBuffer, and queue the data to send
}
However, that code feels kind of brittle to me, compared to the above code.
Any help is most welcome. Thanks :)