I Know there are a bunch of questions related with this topic. Most of the answers states "use a interface" or "create a generic". Tried both and didnt work =( dont know what I'm doing wrong.
Here is the problem: I have two classes: Subjects and Courses. In the main section, I want a function that will receive an id (provided by the user) and look into, for example, a subjectList, trying to find if the subject is there, if yes , return its index. The logic is the same for both Courses and Subjects, so I'm trying to let this function become a bit more generic.
 public static void main(String[] args) {
        
             //Objects created along the code are stored here
             ArrayList<Course> courseList = new ArrayList<>();   
             ArrayList<Subject> subjectList = new ArrayList<>();
        
            public static Integer findObjectById(int id, ArrayList<IStudyDetails> object_list) {
                for (int i = 0; i < object_list.size(); i++) {
                    if (id == object_list.get(i).getId()) {
                        return i;
                    }
                }
                return null;
            }
    int index_subject = findObjectById(subject_id,subjectList);
    }
Here is the Interface: I tried to create this after look into some Stack Overflow related topics.
public interface IStudyDetails{
    int getId();
}
Here is the Course class: (I did hide most of the constructors/gets and setters)
public class Course implements IStudyDetails {
    private int id;
    private String name;
    public int getId() {return id;}}
Here is the Subject class (I did hide most of the constructors/gets and setters)
public class Subject implements IStudyDetails {
    private int id;
    private String name;
    public int getId() {return id;}}
THe error I'm receiving is:
java: incompatible types: java.util.ArrayList<entities.Subject> cannot be converted to java.util.ArrayList<entities.IStudyDetails>
 
     
    