0
처리 방법을 알지 못하면 다음 경고가 표시됩니다. 제가 알 수 있듯이 [Course] 클래스가 있고 [idOrName]이라는 일반 속성이 있습니다. 나는 다음과 같은 worning를 얻을 inseretion 방법을 만들려고 할 때 PR3 클래스 이름입니다일반 경고 - 인클로저에 유형이 없습니다.
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).
합니다.
다음 코드는 경고입니다. set.add (new Course (name, avg)); 당신이 PR3
에 내부 클래스 Course
을 작성 insertCoursesToSet
방법은 static
때문에
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;
}
}
했나 'Course' 클래스와 별도의 파일을 생성합니까? –
중괄호의 들여 쓰기는 거의 이해가되지 않습니다. 수정 해 주실 수 있습니까? 편집을 제안하는 것에 조심 스럽습니다. – skiwi
오류에 대한 자세한 내용은이 답변을 참조하십시오. http://stackoverflow.com/questions/9744639/must-qualify-the-allocation-with-an-enclosing-instance-of-type-geolocation?rq= 1 – skiwi