菜鸟我正处于基础学习阶段,出现以下错误,实在不会了
import java.util.*;
class MapEntryDemo
{
public static void main(String[] args)
{
Maps<String,String> map=new Maps<String,String>();
map.puts("dfb","01");
map.puts("aas","04");
map.puts("bjh","03");
sop(map);
Set<Maps.Entrys<String,String>> maens=map.entrySets();
Iterator<Maps.Entrys<String,String>> it=maens.iterator();
while(it.hasNext())
{
Maps.Entrys<String,String> me=it.next();
sop(me.getKeys()+":::"+me.getValues());
}
}
public static void sop(Object obj)
{System.out.println(obj);}
}
class Maps<K extends Object,V extends Object> extends TreeMap<K,V>
{
private TreeMap<K,V> tm=new TreeMap<K,V>();
public void puts(K key,V value)
{
tm.put(key,value);
}
public static class Entrys<K,V> implements Comparable<Entrys<K,V>>
{
private K key;
private V value;
Entrys(K k,V v)
{key=k;value=v;}
public K getKeys()
{return key;}
public V getValues()
{return value;}
public int compareTo(Entrys<K,V> et)
{
int m=key.compareTo(et.key);
return m;
return 1;
}
}
public Set<Entrys<K,V>> entrySets()
{
Set<Entrys<K,V>> ts=new TreeSet<Entrys<K,V>>();
Set<K> keyset=tm.keySet();
Iterator<K> it=keyset.iterator();
while(it.hasNext())
{
K key=it.next();
ts.add(new Entrys<K,V>(key,tm.get(key)));
}
return ts;
}
public String toString()
{return tm.toString();}
}
编译时总是报出:
MapEntryDemo.java:42: 错误: 找不到符号 int m=key.compareTo(et.key); ^ 符号: 方法 compareTo(K) 位置: 类型为K的变量 key 其中, K是类型变量: K扩展已在类 Entrys中声明的Object1 个错误
|
|