Cloud Stack Ninja

In Java, I have a class Team contains a list of teammate

public class Team{
     private List<Teammate> tm =new ArrayList<>();
     public List<Teammate> getPersons(){return tm;}
     public void addTeammate(String name){tm.add(new Teammate(name));}

//nested class
     public final static class Teammate{
     private String name;
     public String getName(){return this.name;}
     private Teammate(String name){this.name=name;}
     } 
}

After that I want to initialize a Team and add new Teammates to the Team, how can I do it elegant? Thanks!



Read more here: https://stackoverflow.com/questions/64419139/how-can-i-use-a-list-outside-the-class

Content Attribution

This content was originally published by Pichu Sir at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: