First I have a class and the class has a void method:
class IntGroup {
int size;
List<int[]> intervals;
public IntGroup() {
this.size = 0;
this.intervals = new ArrayList<>();
}
public void addInt(int[] interval) {
this.intervals.add(interval);
this.size++;
}
}
Then when I try to create a List, create a new object and call the method
// int[][] intervals
List<IntGroup> list = new ArrayList<>();
list.add(new IntGroup().addInt(intervals[0]));
I got error message error: 'void' type not allowed here list.add(new IntGroup().addInt(intervals[0]));. I tried to change the return type of addInt to List and int, neither worked.