Lambda can only be used with functional interface?

前端 未结 4 1443
盖世英雄少女心
盖世英雄少女心 2020-12-13 20:26

I did this:

public class LambdaConflict
{
    public static void main(String args[]){
        //*
        System.out.println(LambdaConflict.get(
                     


        
4条回答
  •  失恋的感觉
    2020-12-13 21:24

    No. There is no way to "overcome" this. A functional interface must have only one abstract method. Your interface has two:

    interface Intf {
        public T get1(T arg1);
        public T get2(T arg1);
    }
    

    Note: You don't need to annotate your interface as mentioned in comments. But you can use the @FunctionalInterface annotation to get compile time errors if your interface is not a valid functional interface. So it brings you a little bit more security in your code.

    For more see e.g. http://java.dzone.com/articles/introduction-functional-1

提交回复
热议问题