是否可以使用ImageMagick对图像执行连接组件标记?
假设我们有两个有序的数字集合.我们想要逐个元素地计算算术差异.我认为我们需要使用数字列表来模拟"有序的数字集合"的概念.问题是没有为Number定义算术差异(如3-2中的平庸' - ').我可以将所有内容都转换为Double,但我宁愿选择一个干净的解决方案.
public static <E extends Number> List<E> listDifferenceElementByElement(List<E> minuend, List<E> subtrahend) throws Exception {
if (minuend.size() != subtrahend.size()) {
throw new Exception("Collections must have the same size"); //TODO: better exception handling
}
List<E> difference = new ArrayList<E>();
int i = 0;
for (E currMinuend : minuend) {
difference.add(currMinuend-subtrahend.get(i)); //error: The operator - is undefined for the argument type(s) E, E
i++;
}
return difference;
}
Run Code Online (Sandbox Code Playgroud)
任何的想法?