Solved Error with HashSet

Discussion in 'Spigot Plugin Development' started by mrkino99, Feb 18, 2020.

  1. I have this code of line
    Code (Java):
            Collection<CommandSender> recipients = new HashSet<>(Bukkit.getServer().getOnlinePlayers());
     
    and when i compile my plugin, i get this error
    Error:(62, 48) java: cannot infer type arguments for java.util.HashSet<>

    what is that?
     
  2. Compiles fine for me... What java-version are you using?
    Try this:
    Code (Java):
    Collection<CommandSender> recipients = new HashSet<CommandSender>(Bukkit.getServer().getOnlinePlayers());
     
  3. im using java 8, and i have tried it, but it says me redundant arguments
     
  4. Maybe the method returns an array since you are coding in 1.8.8... Try this:
    Code (Text):
    Collection<CommandSender> recipients = new HashSet<>();
    for(Player player: Bukkit.getServer.getOnlinePlayers()) {
        recipients.add(player);
    }
     
  5. Yeah i used that and all good... Im not on 1.8.8, but i didnt see the 1.7.10 prefix, then i selected that