【问题标题】:Java - Get all data from another class stored in a static ListJava - 从存储在静态列表中的另一个类中获取所有数据
【发布时间】:2012-12-02 13:30:26
【问题描述】:

这是我将新人添加到静态列表的 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);
   }
}

// 另一个文件中的另一个类。

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

    // HOW TO GET LIST ?    

    }
}

【问题讨论】:

  • 只需使用DialogInput.person。你试过了吗?

标签: java arrays list class


【解决方案1】:
public class MyView extends ViewPart{
    public void createPartControl(Composite parent){

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

    }
}

【讨论】:

    【解决方案2】:

    试试这个:

    public class MyView extends ViewPart{
    
    
        public void createPartControl(Composite parent){
    
    
           List<String> pList = DialogInput.person;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-23
      • 1970-01-01
      • 2012-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-04
      • 2021-08-07
      相关资源
      最近更新 更多