2013-11-26 4 views
1

그래서 나는 학생들의 목록을 트리 맵에 집어 넣는 방법을 쓰려고하는데 트리 맵은 내 StudentViewcontroller에 있습니다. 나는 그것을 내 글쓰기 방법으로 써 줄 수있다. 당신이 개인 생성자를 가지고 있다면다른 클래스의 개인 생성자를 호출 할 수 있습니까?

public class StudentViewController { 
    //A tree map to store the students 
    private TreeMap<String, Student> studentMap = new TreeMap<String, Student>(); 
+0

studentMap은 생성자가 아닌 StudentViewController의 비공개 필드처럼 보입니다. 포함하는 클래스 외부의 비공개 필드는 직접 액세스 할 수 없습니다. – mattnedrich

+0

** [introspection] (http://docs.oracle.com/javase/tutorial/reflect/member/methodInvocation.html)으로 전화 할 수 있습니다. ** #justsayin ' –

답변

1

는 다음 다른 클래스에서 직접 호출 할 수 있습니다 :

Here is my WriteStudent method so far: 
    Public void WriteStudent(PrintWriter pw) { 
    try{ 
     for (Map.Entry<String, Student> s : studentMap.entrySet()){ 
     } 
    }catch(FileNotFoundException e){ 
    } 
    } 

다음은 studentviewcontroller 내 트리 맵입니다. 그러나 개인 생성자가 없습니다. 클래스에는 TreeMap<String,Student> 유형의 studentMap이라는 필드 (개인 액세스 권한이 있음)가 있습니다. 이것은 개인 생성자입니다.

private StudentViewController() { 
    super(); 
} 
+0

다른 방법으로지도에 액세스하려면 어떻게해야합니까? 수업? – user2918160

+0

'StudentVideoController'클래스의 내부 상태에 액세스하는 하나 이상의 ("이상") get 메소드를 구현하십시오. –

0

다른 클래스의 개인 생성자를 호출 할 수 없으므로 개인 생성자, 메소드 및 변수는 소유자 클래스에서만 호출 할 수 있습니다.

관련 문제