How do you get a lot of objects back in a class type?



  • Got a class.

    class ArrayTaskList {
        public Task[] arrayTask = new Task[10];          //массив для хранения тасков
        ..........
        //Остальные методы на подобие как у ArrayList.
        //метод incoming(x,y) возвращает подмножество объектов, которые попадают в 
        //диапазон (task > from && task < to) 
        public ArrayTaskList incoming(int from, int to){ 
        }
    }
    

    Question: How to return the multiplicity of packagings if it is necessary that the returned type of method incoming(x,y) was ArrayTaskList? Thank you.



  • I'd rectify the initials and the designs:

    public class ArrayTaskList {
        public Task[] arrayTask;
    
    public ArrayTaskList() {
        this.arrayTask = new Task[10];
    }
    
    public ArrayTaskList(Task[] arrayTask) {
        this.arrayTask = arrayTask;
    }
    
    public ArrayTaskList incoming(int from, int to) {
        return new ArrayTaskList(Arrays.copyOfRange(this.arrayTask, from, to));
    }
    

    }


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2