推理变量 T 的下界不兼容:整数

问题描述

我得到以下代码

public static <T extends Comparable<T>> void ispalindrome(T[] array)
{
    //body

}

还有这些数组:

Integer[] intArray = {1,2,5,7,9,7};          
Integer[] intArray2 = {1,1,1};         
String[]  strArray = {"a","b","c","a"};   
String[]  strArray2 = {"a","e","f","a"};  


ispalindrome(intArray);
ispalindrome(intArray2);
ispalindrome(strArray);  
ispalindrome(strArray2);

在我编译之前,当我将鼠标悬停在 ispalindrome 上时,它会显示以下错误

  method ispalindrome in class Main cannot be applied to given types;
  required: T[]
  found: String[]
  reason: inference variable T has incompatible bounds
    upper bounds: Comparable<T>
    lower bounds: String
  where T is a type-variable:
    T extends Comparable<T> declared in method <T>ispalindrome(T[])

我尝试使用 <T extends Comparable<? super T>>,但没有用。

编辑:

我试过了,但没有任何效果

我也有Comparable.java

public interface Comparable<T> {
    
    
    int compareto(T other);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)