小编Gus*_*Gus的帖子

PriorityQueue:学生不能转换为java.lang.Comparable

我正在使用PriorityQueue结构来获取用户设置的一些字段,这是代码的一部分:

package gqg;

import java.util.Queue;

public class Student {
     //variables (ID, Name, ...), constructors, getters and setters...

Queue<Student> StudentQueue = new PriorityQueue<Student>();

public void Add() { //method to add the student at Queue
    for(int x=0; x<1; x++) {
        Student st = new Student();
        System.out.println("+---------------------------+\n"
                         + "|   Students Registration   |\n"
                         + "+---------------------------+");
        System.out.println("| Type the student's ID:");
        stu.setID(user.nextInt());
        System.out.println("| Type the student's name:");
        stu.setName(user.next());
        System.out.println("| Type the student's age:");
        stu.setAge(user.nextInt());
        //and other fields...

        StudentQueue.add(st);
    }
    System.out.println("Done. Student has been added successfuly\n"); …
Run Code Online (Sandbox Code Playgroud)

java priority-queue

1
推荐指数
1
解决办法
6407
查看次数

标签 统计

java ×1

priority-queue ×1