gpt4 book ai didi

java - 为什么这会给我一个边界错误?

转载 作者:行者123 更新时间:2023-12-02 00:07:27 25 4
gpt4 key购买 nike

我有一个自定义的“堆”类:

public class Heap<T extends Comparable<T>>
{
ArrayList<T> heapList;


public Heap()
{
heapList = new ArrayList<T>();

}

和自定义“Process”类:

public class Process {
private int processID, timeUnitsRequired, priority, timeOfArrival;

public Process(int processID, int timeUnitsRequired, int priority, int timeOfArrival) {
this.processID = processID;
this.timeUnitsRequired = timeUnitsRequired;
this.priority = priority;
this.timeOfArrival = timeOfArrival;
}

但是如果我尝试创建一个新的进程堆,例如 Heap<Process> processHeap = new Heap<Process>();我收到以下错误:

Bound mismatch: The type Process is not a valid substitute for the bounded parameter > of the type Heap

这是为什么呢?我似乎无法弄清楚。

最佳答案

流程未实现 Comparable

关于java - 为什么这会给我一个边界错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13556745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com