Access nested class list from outer class

I have a class that has a static nested class with two lists. And one of the functions within the outer class has the return type of this nested class. And this class takes in two lists in the constructor.

public class A {

  public static class Data {

  List<? extends Model> createdObjects;
  List<? extends Model> removedObjects;

  public Data(List<? extends Model> createdObjects , List<? extends Model> removedObjects) { 
        this.createdObjects = createdObjects;
        this.removedObjects  = removedObjects; 
  }
    public List<? extends Model> getCreatedObjects() {
        return this.createdObjects;
    }
    public List<? extends Model> getRemovedObjects() {
        return this.removedObjects;
    }
  }

List<Model> modelList = createObject();
modelList.add(model);
// Question - How should I be returning the data in the createdObjects? 
//Is this the correct way to create the data object and return it?
A.Data data = new A.Data(modelList, Collection.EMPTY_LIST,   Collection.EMPTY_LIST );
return data;
}

}

So from I what know, createdObject can take a list of Model or List of an object that extends Model. So in my case, the createObject() creates a list, let's say List class, that extends from Model1 which in turn extends from Model. So I suppose I can create a list of MyModel, and then call the Data constructor along with two other empty lists (for the sake of discussion). Could anyone confirm if this would be a correct way of doing it?



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)