我决定用Java编写一些常见的高阶函数(map,filter,reduce等),这些函数通过泛型是安全类型的,并且我遇到了在一个特定函数中匹配通配符的问题.
为了完整,函子接口是这样的:
/**
* The interface containing the method used to map a sequence into another.
* @param <S> The type of the elements in the source sequence.
* @param <R> The type of the elements in the destination sequence.
*/
public interface Transformation<S, R> {
/**
* The method that will be used in map.
* @param sourceObject An element from the source sequence.
* @return The element in the destination sequence.
*/
public R apply(S sourceObject);
}
Run Code Online (Sandbox Code Playgroud)
令人不安的功能就像一个 …