Student.java:import java.util.*;
public class Student
{
    private int id;
    private String name;
    private int    chinese;
    private int    math;
    private int    english;
    static  TreeMap mapChinese=new TreeMap();
    static  TreeMap mapStu=new TreeMap();    public Student(int id,String name,int chinese,int math,int english)
    {
         this.id=id;
         this.name=name;
         this.chinese=chinese;
         this.math=math;
         this.english=english;
         mapChinese.put(chinese, this);  //这句提示错误???????????????
         mapStu.put(name, this);
    }
    
    public String toString() {
     return("学号:"+id+"姓名:"+name+"语文成绩:"+chinese+"数学成绩:"+math+"英语成绩"+english);
        }
}==============================myMain.java:import java.util.*;public class myMain { /**
 * @param args
 */

public static void sortChinese()
{
for(Iterator it=Student.mapChinese.keySet().iterator() ; it.hasNext(); )
{
System.out.println(Student.mapChinese.get(it.next()));
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Student stu1=new Student(1,"aaa",88,99,89);
Student stu2=new Student(2,"bbb",56,36,56);
Student stu3=new Student(3,"ccc",96,89,87);

System.out.println(Student.mapStu.get("aaa")); //通过名字查询详细信息
sortChinese();  //语文成绩排序 }}
===========================提示错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
The method put(Object, Object) in the type TreeMap is not applicable for the arguments (int, Student) at Student.<init>(Student.java:19)
at myMain.main(myMain.java:18)
mapChinese.put()里的2个参数是Object类型的,我想放什么就放什么进去,他还提示我不准放(int, Student)型的
真TM搞笑?????????????????

解决方案 »

  1.   

    int不是Object类型所以不行,在JCreator中应该也是不可以的。应该把int用它的包装类Integer
      

  2.   

    可能是eclipse的设置问题,在Preferences--Java--compiler看看选择的是不是5.0或者以上,我当初就是默认选的是1.4所以无法使用范型
      

  3.   

    int 是基本类型,需要用Integer包装类转换
      

  4.   

    我大惊小怪了
    应该是JCreator编译时把错误检查等级调低了
      

  5.   

    上面的搞笑吧~
    1.5 
    int 可以转成Integer 谢谢