Groovy web console

subscribe to the feed Subscribe
to this
site

add_deeply_nested_list

Published 3 months ago by solvingj
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
class MyItem{
}

class MyList {
    private List<MyItem> _myItems = []
	
    List<MyItem> getMyItems(){
      return _myItems
    }
	
    void add(MyItem myItem){
     _myItems.add(myItem)
    }

    Integer size(){
        return _myItems.size()
    }
}

class UtilClass {
    private MyList _myList
    UtilClass(){
        _myList = new MyList()
        _myList.add(new MyItem())
    }

    MyList getMyList(){
        return _myList
    }
}


class OuterClass {
    UtilClass utilClass
    OuterClass(){
        utilClass = new UtilClass()
    }
    
    void run(){
        println(utilClass.getMyList().size())
        utilClass.getMyList().add(new MyItem())
        println(utilClass.getMyList().size())
    }
}

new OuterClass().run()