Java - 从存储在静态List中的另一个类中获取所有数据

时间:2012-12-02 13:30:27

标签: java arrays list class

这是Dialog类,我将新人添加到静态列表

public class DialogInput extends Dialog{
   public static List<Person> person = new LinkedList<Person>();

   Text txtName;    

   @Override
   protected Control createPartControl(Composite parent){
     ...
     txtName = new Text(parent, SWT.NONE);
   }

   @Override
   protected void okPressed(){
      Person p = new Person();
      p.setName(txtName.getText());
      person.add(p);
   }
}

//另一个CLASS在另一个文件中。

public class MyView extends ViewPart{
    public void createPartControl(Composite parent){

    // HOW TO GET LIST ?    

    }
}

2 个答案:

答案 0 :(得分:1)

public class MyView extends ViewPart{
    public void createPartControl(Composite parent){

    // HOW TO GET LIST ? 
    List<Person> personList = DialogInput.person;   

    }
}

答案 1 :(得分:0)

试试这个:

public class MyView extends ViewPart{


    public void createPartControl(Composite parent){


       List<String> pList = DialogInput.person;
    }
}