There are two different problems here. First, your compareTo method assumes it can call compareTo() on the return value of Student.getStudentId(). Since the compiler has no idea what type that method will return, there's an error. To fix this, you can constrain the type parameters for Student by declaring it as
Then the compiler knows that getStudentId() always returns a Comparable. That's one problem. The second one is that you've accidentally made the
word "Student" into a type parameter for your SortStudentById class, which is definitely not what you want! Just declare that class as
With these two changes
you should be all set.