1

When I create a generic list in my main and then pass it as an argument in Utils.printUser(users), I get a compilation error despite that Instructor is a subclass of User, can anyone explain me why this happens?

public class Main {
    public static void main(String[] args) {
        var users = new GenericList<Instructor>();
        Utils.printUser(users);
    }
}

public class Instructor extends User{
    //...
}

public class Utils {
    public static void printUser(GenericList<User> user){
        //...
    }
}

public class GenericList <T>{
    private T[] items = (T[])new Object[10];
}

0 Answers0