Search code examples
javaminecraftbukkit

'Wildcard' Importing for Interface


I'm looking to create an interface for my plugin which uses a different class depending on the servers version.

I've tried to include the following in my interface class:

Map<String, EntityPlayer> getPlayers();

However 'EntityPlayer' is imported depending on version, and so it's not viable for me to do this. I essentially need it to be a 'wildcard', where it can be any EntityPlayer import. Then in classes where my interface is implemented, I can use the per-version import.

Hopefully this clarifies what I'm trying to accomplish and what I have done so far.

Thanks all.


Solution

  • You can use a generic Interface something like this

    interface YourInterface<T> {
       Map<String, T> getPlayers();
    }
    

    you could also use a more specific constraint if EntityPlayer is derived from a parent class e.g

    interface YourInterface<T extends EntityParentClass> {
       Map<String, T> getPlayers();
    }