2017-05-24 8 views
-1
class MyMap<K,V> { 

    private Map<K,V> map = new HashMap<K,V>(); 
    ... 

    public void add(K key, V value){ 
     map.put(key,value); 
    } 

    private load(String filePath){ 
     ... 
     while(true){ 
     ... 
     People key = new People(); 
     Information info = new Information(); 
     ... 
     this.add(key, info); 
    } 
    } 
} 

그것은 불평 : 그것은 것입니다 일반과 특이없이일반지도가 작동하지 않는 이유는 무엇입니까?

public class Main { 

    public static void main(String[] args){ 
     MyMap<People, Information> map = new MyMap<>(); 
     People p = new People(); 
     Information i = new Information(); 
     map.add(p, i); 
    } 
} 
+0

개인지도 map = new HashMap (); – user697911

+0

나는 그것의 외부에서 그것을 사용하기 시작하지 않았다. 로드 메서드에서 오류가 발생했습니다. "this.add (people, info)"; 이 클래스 자체가 이미 오류를보고하고 있습니다. – user697911

+0

당신이 저장하고있는 것이 항상'People' 키와'Information' 값이라면 이것이 일반적인 것이 아닐 것이라고 생각합니다. –

답변

0

원래 올바른 방법은이 클래스를 행사할 컴파일 시간 오류가 발생했습니다

0

당신이 해시 맵에 직접 값을 삽입하려고 :

add(K,V) is not applicable for the arguments "[People, Information]". 
관련 문제