Reteras Remus
Reteras Remus

Reputation: 933

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

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 ?    

    }
}

Upvotes: 0

Views: 385

Answers (2)

Kumar Vivek Mitra
Kumar Vivek Mitra

Reputation: 33534

Try this:

public class MyView extends ViewPart{


    public void createPartControl(Composite parent){


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

Upvotes: 0

Narendra Pathai
Narendra Pathai

Reputation: 41955

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

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

    }
}

Upvotes: 1

Related Questions