Use of Java 8 Lambdas with Generics

后端 未结 4 1799
执念已碎
执念已碎 2021-02-10 14:37

Is it possible to do this using Predicate interface.

I have a client class that utilizes functions provided by a MathUtility class. Whatever the Mathmatical operation it

4条回答
  •  心在旅途
    2021-02-10 14:54

    The answer is yes, that should be possible. The you defined is not known to have the method "sum", therefore the compiler complains. Try to define

    public interace SumInterface {
       public int sum(int a, int b);
    }
    

    (I haven't tried this code in IDE but this should do the trick)

提交回复
热议问题