In my Java class I have this property defined:
private ArrayList requests;
and this is the constructor in the class:
public LeaveRecord() {
this.requests = new ArrayList<Request>();
this.daysLeft = ALLOWANCE;
}
in another method I’m trying to return the relevant Request object based on the index of the ArrayList.
public Request getRequestAt(int index) {
try {
return this.requests.get(index);
} catch (IndexOutOfBoundsException e) {
return null;
}
}
but I’m getting an error on the return line (line 3 in the above snippet) that says it requires leaverecord.Request but found java.lang.Object.
I don’t know what could be wrong, as I defined the ArrayList to be of type Request.
Could someone point me in the right direction? Thanks.
change it to
However compiler should have show you the below warning when you say
ArrayList is a raw type. References to generic type ArrayList<E> should beparameterized