I got the following code:
public static <T extends Comparable<T>> void isPalindrome(T[] array)
{
//body
}
and also these arrays:
Integer[] intArray = {1,2,5,7,9,0,7};
Integer[] intArray2 = {1,1,2,2,2,2,1,1};
String[] strArray = {"a","b","c","c","b","a"};
String[] strArray2 = {"a","b","c","e","f","a"};
isPalindrome(intArray);
isPalindrome(intArray2);
isPalindrome(strArray);
isPalindrome(strArray2);
before I compile and when I hover over ispalindrome it shows me the following error:
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[])
I tried to use <T extends Comparable<? super T>> but it didn't work.
Edit:
I tried but nothing works for me
I have also Comparable.java class
public interface Comparable<T> {
int compareTo(T other);
}
lang-java
Comparablein yourisPalindromesignature.compareTo()instead ofequals()?