0
import java.util.*;

class MyComp<Subject> implements Comparator<Subject> {
    public int compare(Subject s1, Subject s2) {
        return s1.year - s2.year;
    }
}

public class Subject {
    String subjectID;
    int sem;
    String dept;
    public int year;
    String subjectName;
    int theortical;
    int practical;
    int tutorial;
}

I am facing a problem while compiling cannot find symbol s1.year. Same thing for s2.year.

Pshemo
  • 122,468
  • 25
  • 185
  • 269
Abhishek
  • 49
  • 6
  • 3
    `class MyComp` defines generic type with name `Subject` which has nothing to do with `Subject` class. Your code is same as `class MyComp implements Comparator` where you are trying to access `year` from `T` type. Remove that `` from `MyComp`. Now where is that duplicate... – Pshemo Feb 25 '17 at 06:36
  • Other potential duplicate: http://stackoverflow.com/questions/22852512/java-compiler-error-with-generics-and-an-iterator – Pshemo Feb 25 '17 at 06:52
  • related: [What does a “Cannot find symbol” compilation error mean?](http://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean) – Pshemo Feb 25 '17 at 17:42

0 Answers0