相关疑难解决方法(0)

85
推荐指数
4
解决办法
11万
查看次数

Java泛型 - 实现像map这样的高阶函数

我决定用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)

令人不安的功能就像一个 …

java generics functional-programming wildcard matching

8
推荐指数
2
解决办法
3150
查看次数