在java源代码上运行ant构建时遇到以下错误:
[javac] /home/path/to/my/java/function/VarStatusLog.java:28: error: no suitable method found for sort(List<VarStatusMsg<? extends Number>>)
[javac] Collections.sort(logMsg);
[javac] ^
[javac] method Collections.<T#1>sort(List<T#1>) is not applicable
[javac] (inference variable T#1 has incompatible bounds
[javac] equality constraints: VarStatusMsg<? extends Number>
[javac] upper bounds: VarStatusMsg<CAP#1>,Comparable<? super T#1>)
[javac] method Collections.<T#2>sort(List<T#2>,Comparator<? super T#2>) is not applicable
[javac] (cannot infer type-variable(s) T#2
[javac] (actual and formal argument lists differ in length))
[javac] where T#1,T#2 are type-variables:
[javac] T#1 extends Comparable<? super T#1> declared in method <T#1>sort(List<T#1>)
[javac] T#2 extends Object declared in method <T#2>sort(List<T#2>,Comparator<? super T#2>)
[javac] where CAP#1 is a fresh type-variable:
[javac] CAP#1 extends Number from capture of ? extends Number
我在ant构建中使用JDK1.8。请注意,windows上的eclipse不会抛出错误,但是当我在linux上从命令行运行时,会得到错误。有人能帮我吗?提前谢谢!
1条答案
按热度按时间9wbgstp71#
我得说
VarStatusMsg
不实现接口Comparable<VarStatusMsg>
. 签字人sort
你使用的方法是public static <T extends Comparable<? super T>> void sort(List<T> list)
. 要么让你的VarStatusMsg
实现接口Comparable<VarStatusMsg>
,或者Comparator<VarStatusMsg>
作为第二个论据sort
.顺便说一句,你可以打电话给我
logMsg.sort(null)
而不是Collections.sort(logMsg)
或者logMsg.sort(myNiceComparator)
而不是Collections.sort(logMsg, myNiceComparator)
. 这个Collections
方法仅委托给List
现在。