[英]Code in Eclipse doesn't work in IntelliJ
So I'm switching from Eclipse to IntelliJ after 2 days I saw a weird problem. 因此,两天后我看到一个奇怪的问题,就从Eclipse切换到IntelliJ。 When I copy the exact same code from Eclipse to IntelliJ, the code won't work in IntelliJ. 当我将完全相同的代码从Eclipse复制到IntelliJ时,该代码将无法在IntelliJ中使用。
Code: 码:
public class Main extends JavaPlugin {
public void onEnable() {
}
public int number = 10;
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Console Only");
return true;
}
Player player = (Player) sender;
if (cmd.getName().equalsIgnoreCase("bomb")) {
if(args.length == 0){
player.sendMessage("You must specify a player");
return true;
}
Player target = Bukkit.getServer().getPlayer(args[0]);
if(target == null){
player.sendMessage("Couldn't find that player!");
return true;
}
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
public void run() {
if (number != -1) {
if (number != 0) {
target.sendMessage("§a§l" + number + "§7 until you will explode!");
number--;
} else {
number--;
Location loc = target.getLocation();
World world = Bukkit.getServer().getWorld("world");
world.createExplosion(loc, 2F);
}
}
}
}, 0, 20L);
}
return true;
}
}
This code works in Eclipse but not in IntelliJ. 此代码在Eclipse中有效,但在IntelliJ中无效。 IntelliJ says that I need to add a 'final' to this part of the code: IntelliJ说,我需要在代码的这一部分添加一个“ final”:
Player target = Bukkit.getServer().getPlayer(args[0]);
But when I do that the plugin just doesn't work anymore. 但是当我这样做时,该插件就不再起作用了。 Why does it work in Eclipse but not in IntelliJ? 为什么它在Eclipse中起作用,但在IntelliJ中却不起作用?
What you are seeing is probably not a compile error, but an IntelliJ code inspection. 您看到的可能不是编译错误,而是IntelliJ代码检查。 These give warnings, like a red underline (like compile error), a yellow underline (like compiler warning), etc. If you place your caret somewhere that's marked red, and press alt+enter, you should be given some choices, amongst them something like "edit inspection settings". 它们会发出警告,例如红色下划线(例如编译错误),黄色下划线(例如编译器警告)等。如果将插入符号放置在标记为红色的位置,然后按alt + enter,则应该在其中选择一些选项。例如“编辑检查设置”。 Here you can disable this inspection. 您可以在此处禁用此检查。 Or, you could just start using final
.. 或者,您可以开始使用final
..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.