首页 > 解决方案 > 运算符 <= 不能应用于“E”、“E”、泛型类

问题描述

我想合并到 JAVA 中的两个linkedLists,但是当我想比较数据h1.data <= h2.data时,我得到那个运算符<=不能应用于'E' 'E'

这是我的通用类SLLNode<E>

public class SLL<E extends Comparable<E>>  {
    private SLLNode<E> first;
    public SLL(){
        this.first=null;
    }

现在当我想实现该merge方法时

public SLLNode<E> merge (SLLNode<E> h1, SLLNode<E> h2){
    if (h1 == null)
    {
        return h2;
    }
    if (h2 == null){
        return h1;
    }

    SLLNode<E> mergedHead = null;
    if(h1.data<=h2.data)

我收到上面列出的错误。

标签: javamergelinked-listgeneric-list

解决方案


推荐阅读