简体   繁体   English

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

[英]Java - Get all data from another class stored in a static List

This is the Dialog class where I add new person to a static List 这是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);
   }
}

// ANOTHER CLASS in a different file. //其他文件中的另一个类。

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

    // HOW TO GET LIST ?    

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

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

    }
}

Try this: 尝试这个:

public class MyView extends ViewPart{


    public void createPartControl(Composite parent){


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java-使用其他类的静态列表 - Java - Using a static list from another class Java从另一个类获取对象列表 - Java Get the List of an Object from another Class 我们能否将 Arraylist 从 class 调用到另一个 class,并且可以被“另一个”class 中的所有方法使用? 无 static - Java - Can we call a Arraylist from a class to another class, and can be used by all methods in the 'another' class? No static - Java 如何从另一个 class 获取存储在 hashmap 中的数据 - How to get the data stored inside the hashmap from another class 从静态Java获取公共类的数据 - get data from public class from static java Java:将List &lt;&gt;项目从一个类获取到另一个类的JComboBox中 - Java: Get List<> Items from one class into JComboBox of another class 从主类中的静态方法访问列表,而在Java中其他类的另一种方法中访问列表 - accessing a list from a static method in main class, in another method of different class in java 如何从 Java 应用程序中的另一个类访问在实用程序类中声明的公共最终静态列表? - How can I access to a public final static list declared into an utility class from another class in a Java application? 从java中的另一个类访问静态变量 - Accesing static variable from another class in java 从另一个java类调用静态方法 - Calling static method from another java class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM