I'm experiencing the following warning without a clue how to handle it. As you can see I have a [Course] Class, with generic property [idOrName]. when I try to create the inseretion method I get the following worning:
No enclosing instance of type PR3 is accessible. Must qualify the
allocation with an enclosing instance of type PR3 (e.g. x.new A()
where x is an instance of PR3).
where PR3 is the class name.
following is the code, the warning is at the line set.add(new Course(name,avg));
private static void insertCoursesToSet(Set<Course> set, int n, int it) {
Scanner s = new Scanner(System.in);
if(it==1)
for(int i=0 ; i<n ; i++){
System.out.println("Please enter name:");
s.nextLine(); //clear buffer
String name = s.nextLine();
System.out.println("Please enter avg:");
float avg = s.nextFloat();
set.add(new Course<String>(name,avg));
}
else
for(int i=0 ; i<n ; i++){
System.out.println("Please enter id:");
Integer id = s.nextInt();
System.out.println("Please enter avg:");
float avg = s.nextFloat();
set.add(new Course<Integer>(id,avg));
}
}
public class Course<E>{
private E idOrName;
private float avg;
public Course(E idOrName, float avg){
this.idOrName = idOrName;
this.avg = avg;
}
}