我在下面的代码中得到了一个 ClassCastException,这对我来说没有多大意义,因为targetObject
它是一个 Comparable 并且current
是一个 ToBeFound。整数和字符串来自哪里?
ToBeFound origin = new ToBeFound();
public ToBeFound findWrapper(Comparable targetObject)
{
return find(origin, targetObject);
}
private ToBeFound find(ToBeFound current, Comparable targetObject)
{
if (current == null)
{
return null;
}
System.out.println(targetObject.compareTo(current.getValue()));
// Exception in thread "main" java.lang.ClassCastException:
// java.lang.Integer cannot be cast to java.lang.String
return new ToBeFound();
}
//body of main() that calls the methods
master.find( (Comparable) scanner.next());
// Scanner is a java.util.Scanner scanning System.in