我一直在做一个练习题。这个想法是我应该采用一个链表,然后将一个一元转换器应用于列表,并返回修改后的列表。我没有应用特定的更改,只是处理并返回一个链接列表。这是细分以及说明提供的 UnaryTransformer 方法:
“如果 L 是 Q 类型的对象链表的头部,而 R 是 UnaryTransformer,则 transformAll(L,R) 是通过将 R 按顺序应用于 L 中的每个对象而获得的对象链表。”
{@code UnaryTransformer} objects are used to represent functions with the signature:
public interface UnaryTransformer<Q> {
/**
* Returns the result of applying a function modeled by
* {@code UnaryTransformer} to the given object
*
* @param object the object to transform
* @return the result of applying a function
*/
Q apply(Q object);
}
到目前为止,我有这段代码,但它没有编译。
public static transformAll(Node L, R) {
if (L != null) {
LinkedList<Q> sequence = new LinkedList<Q>();
for (int i = 0; i < size(); i++) {
if (p.apply(get(i))){
sequence.add(get(i));
}
}
return sequence;
}
}