How can I tell the compiler that I am sure that this generic type has the method get?
I have done a little bit of research, and let the T extends some interface might help. example1 example2
But what is the exact interface I have to extends for the method get?
How could I search for this interface in IDE? So that next time, I could avoid asking if it is some methods other than get
private static <T> ArrayList<T> trimstartend(ArrayList<T> rows,Date startdate ,Date endDate){ // if the date of current row is before the startdate, remove it for (Iterator<T> iterator = rows.iterator(); iterator.hasNext();) { T row = iterator.next(); if ((Date)row.get("Date").before(startdate) ) { // this line doesn't compile! Unresolved method get iterator.remove(); } } // if the date of current row is after the enddate, remove it for (Iterator<T> iterator = rows.iterator(); iterator.hasNext();) { T row = iterator.next(); if ((Date)row.get("Date").after(endDate)) { // this line doesn't compile! Unresolved method get iterator.remove(); } } return rows; }
Actually T is hashmap. But let us make it generic here.