private static transient JavaPlugin myPlugin = null;
public SomeClass(JavaPlugin plugin) {
if (myPlugin == null) myPlugin = plugin;
}
public <T> T getPlugin(Class<? extends JavaPlugin> plugin) {
return (T)myPlugin; // return casted version of "myPlugin" form above
}
Calling it in the line below works just fine, and trying to use a class that doesn't extend JavaPlugin will throw a compile time error. But how can I make it so the above function works without requiring @SuppressWarnings("unchecked")
??
MyPlugin nc = this.getPlugin(my.main.package.MyPlugin.class);