title: Getting a List from another class
body: <p>I've been trying to figure out how to make a List from classA accessible for ClassB
  I've tried creating an instance/object of the list but it always returns empty when I get the size of the list (while in the main class its not empty).</p>
  
  <p><strong>Example:</strong></p>
  
  <p>ClassA:</p>
  
  <pre><code>List&lt;String&gt; players = new ArrayList&lt;String&gt;();
  </code></pre>
  
  <p>If i used <code>players.size()</code> here it would return 2 for example</p>
  
  <p>in ClassB I tried the following:</p>
  
  <pre><code> ClassA classA = new ClassA();
   List&lt;String&gt; newList = classA.players;
  </code></pre>
  
  <p><code>newList.size()</code> will always return 0 no matter what.</p>
  
  <p>I've also tried using a getter but that doesn't seem to make a difference.</p>
  
  <p><strong>Example:</strong></p>
  
  <p>ClassA:</p>
  
  <pre><code>List&lt;String&gt; players = new ArrayList&lt;String&gt;();
  public List&lt;String&gt; getList(){
      return this.players;
  }
  </code></pre>
  
  <p>ClassB: </p>
  
  <pre><code>ClassA.getList().size()
  </code></pre>
  
  <p>This will also always return 0</p>
  
  <p>How would I properly do this? I tried using a static and that seemed to work but i've been told: </p>
  
  <blockquote>
    <p>"Static is not the right tool for the job. It's a memory management
    tool, not an access modifier."</p>
  </blockquote>
  
  <p>He told me:</p>
  
  <blockquote>
    <p>Instead of static and instead of creating new instances, you can pass
    instances to other classes by adding them as parameters to the
    constructor</p>
  </blockquote>
  
  <p>However I don't really get what he means. If someone could explain this with an example that would be amazing. Thanks in advance!</p>
  
  <p><strong>Edit:</strong> Since a lot of you don't quite get where i want to go with this i'll post my source:
  <strong>refered to as ClassA in the example</strong></p>
  
  <pre><code>public class TeamManager {
  
  String prefix = new Messages().prefix;
  List&lt;String&gt; players = new ArrayList&lt;String&gt;();
  List&lt;String&gt; human = new ArrayList&lt;String&gt;();
  List&lt;String&gt; infected = new ArrayList&lt;String&gt;();
  
  void join(Player p){
      if(!players.contains(p.getName())){
          players.add(p.getName());
          teleportToLobby(p);
          for (String temp : players) {
              Bukkit.getPlayer(temp).sendMessage("§e§l"+p.getName()+ " has joined infection. §7("+players.size()+"/16)");
          }
      }else{
          p.sendMessage(prefix + "§cFailed. You are already in the game!");
      }
  }
  void leave(Player p){
      if(players.contains(p.getName())){
          p.teleport(Bukkit.getWorlds().get(0).getSpawnLocation());
          players.remove(p.getName());
          for (String temp : players) {
              Bukkit.getPlayer(temp).sendMessage("§7§l"+p.getName()+ " has left infection. §7("+players.size()+"/16)");
          }
      }else{
          p.sendMessage(prefix + "§cYou are not in a game!");
      }
  }
  void addToHumans(String playername){
      human.add(playername);
  }
  void removeFromHumans(String playername){
      human.remove(playername);
  }
  void addToInfected(String playername){
      infected.add(playername);
  }
  void removeFromInfected(String playername){
      infected.remove(playername);
  }
  
  void teleportToLobby(Player p){
      Location lobby = getLocFromConfig("lobby");
      if(lobby != null){
          p.teleport(lobby);
          p.sendMessage(prefix + "§aSuccessfully added to game!");
      }else{
          p.sendMessage(prefix + "§cLobby not set! Make sure to set a lobby using /infection setlobby");
      }
  }
  void startGame(){
      /*if(human.size() &gt;= 4){
      }*/
      for (String temp : players) {
          Bukkit.getPlayer(temp).sendMessage("Game will start shortly!");
      }
  }
  Location getLocFromConfig(String locationName){
      if(Main.plugin.getConfig().get("lobby") != null){
          double x = Main.plugin.getConfig().getInt(locationName+".x");
          double y = Main.plugin.getConfig().getInt(locationName+".y");
          double z = Main.plugin.getConfig().getInt(locationName+".z");
          World world = Main.plugin.getServer().getWorld(Main.plugin.getConfig().getString(locationName+".world"));
          Location l = new Location(world, x, y, z);
          return l;
      }else{
          Bukkit.getLogger().warning("[Infection] Lobby has not been set!");
          return null;
      }
  }
  int getPlayersInLobby(){
      return players.size();
  }
  
  public List&lt;String&gt; getPlayers(){
      List&lt;String&gt; players = this.players;
      return players;
  }
  public List&lt;String&gt; getHumans(){
      return human;
  }
  public List&lt;String&gt; getInfected(){
      return infected;
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Events class (referred to in the example as ClassB)</strong></p>
  
  <pre><code>public class Events implements Listener{
  
  TeamManager teamman = new TeamManager();
  List&lt;String&gt; players = teamman.getPlayers();
  List&lt;String&gt; humans = teamman.getHumans();
  List&lt;String&gt; infected = teamman.getInfected();
  @EventHandler
  public void onPlayerJoin(PlayerJoinEvent e){
      //Player p = (Player) e.getPlayer();
      //e.setJoinMessage("["+lvl+"]" + e.getPlayer().getName() +"has joined the game!");
      //p.setDisplayName("[lvl1]"+p.getName());
  
  }
  @EventHandler
  public void onPlayerDamage(EntityDamageByEntityEvent  e){
      if(e.getEntity() instanceof Player){
          Player p = (Player) e.getEntity();
          Bukkit.getServer().broadcastMessage("Players: "+ players);
          if(players.contains(p.getName())){
              if((p.getHealth() - p.getLastDamage()) &lt; 1){
                  for (String temp : players) {
                      Bukkit.getPlayer(temp).sendMessage("§c"+p.getName()+" got infected by "+p.getKiller().getName()+"!");
                  }
                  e.setCancelled(true);
                   p.setHealth(20);
                   teamman.addToInfected(p.getName());
                   teamman.removeFromHumans(p.getName());
                   p.sendMessage("§cYou have been infected!!");
              }
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>As said above i want to be able to access the lists from TeamManager and use them in Events. And as explained <code>players</code> is empty in the Events class. I hope this helps.</p>