에 나는 내가 트리 맵에 넣어 객체를 정의하는 다음 두 개의 클래스를하고자했다 나는 다음 트리 맵하고 싶습니다 :오류 <개체, 개체> TreeMap의
import java.util.TreeMap;
// In main ...
TreeMap<GeneKey, GeneValue> samples = new TreeMap<GeneKey, GeneValue>();
String a = "test";
int b = 100;
String c = "test again";
String d = "test yet again";
// Try to put these objects into the tree map.
samples.put(new GeneKey(a, b) ,new GeneValue(c,d))
을하지만, 나는 다음과 같은 오류가 발생합니다 :
을Exception in thread "main" java.lang.ClassCastException: GeneKey cannot be cast to java.lang.Comparable
왜 TreeMap 키를 사용하여 설정할 수 없는지 알고 싶습니다. 내 TreeMap을 초기화 할 때 해당 개체를 지정 했더라도 GeneKey : GeneValue 값. 이 두 개체를 .put()하기 위해지도를 초기화하는 방법.
는
'GeneKey'에'Comparable'을 구현 하시겠습니까? – Reimeus
이것은 거의 정확하게 http://stackoverflow.com/questions/28178337/returning-a-sortedset/28178380#28178380의 속임수입니다. –