Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java类型推断错误_Java_Lambda_Types_Functional Programming - Fatal编程技术网

Java类型推断错误

Java类型推断错误,java,lambda,types,functional-programming,Java,Lambda,Types,Functional Programming,我在玩用函数表示对的游戏。我有一个Pair版本工作,它有两个相同类型的元素。我接着做了一对a,B。当我编译以下代码时,我得到以下错误消息: fp2.java:34: error: method pairing in class fp cannot be applied to given types; return fp.<A,B>pairing().apply(a).apply(b); ^ required: no arguments fou

我在玩用函数表示对的游戏。我有一个
Pair
版本工作,它有两个相同类型的元素。我接着做了一对
a,B
。当我编译以下代码时,我得到以下错误消息:

fp2.java:34: error: method pairing in class fp cannot be applied to given types;
    return fp.<A,B>pairing().apply(a).apply(b);
             ^
  required: no arguments
  found: no arguments
  reason: actual and formal argument lists differ in length
1 error    

请尝试将代码缩减到绝对最小值。如果删除
apply()
,错误消息是否会保留?什么是
fp
?我看不到它在代码中的任何地方被定义。@JacobG。多好的一课啊
fp
是处理另一个文件中定义的一对
a,a
。这就是解决办法!
public class fp2 {

  interface First<A,B> {
    Function<B,A> apply(A a);
  }

  interface Second<A,B> {
    Function<B,B> apply(A a);
  }

  interface Pair<A,B> {
     A apply(First<A,B> fst);
     B apply(Second<A,B> fst);
  }

  interface I2<A,B> {
    Pair<A,B> apply(B b);
  }

public static <A,B> I3<A,B> pairing() {
    return a -> b -> new Pair<A,B> () {
      public A apply(First<A,B> fst) { return fst.apply(a).apply(b); }
      public B apply(Second<A,B> snd) { return snd.apply(a).apply(b); }
    };
  }

  public static <A,B> Pair<A,B> pair(A a, B b) {
    return fp.<A,B>pairing().apply(a).apply(b);
  }

  public static <A,B> First<A,B> fst() {
    return a1 -> a2 -> a1;
  }

  public static <A,B> Second<A,B> snd() {
    return a1 -> a2 -> a2;
  }

  public static void main(String[] args) {
    Pair<Integer,Double> p1 = pair(1,2.0);
    System.out.println(p1.apply(fst()));
    System.out.println(p1.apply(snd()));
  }
}