Home > Back-end >  What's the difference between two ways of lambda
What's the difference between two ways of lambda

Time:09-28

 
@ FunctionalInterface
Public interface ConInterface2 {
Void doSom (List d);
}



 public class MainTest {
Public static void main (String [] args) {
List A=new ArrayList ();
A.a dd (" aaa ");
A.a dd (" BBB ");
//a
ConInterface2 cif=(gg) - & gt; System. The out. Println (gg. Get (1));
Cif. DoSom (a);

//way.
Bb (a, q) (List - & gt; {
System. The out. Println (q.g et (1));
});
}
Private static void bb (List w, ConInterface2 c2) {
C2. DoSom (w);
}

}


The results
 BBB 
BBB

CodePudding user response:

Way is the lambda expressions assigned to the corresponding functional interface class
Way 2 is the lambda expressions as a parameter to method directly to the
Although there is no use new, but every lamba expression will be the compiler to generate a new corresponding functional interface instance

CodePudding user response:

reference 1st floor sotondolphin response:
way one is the lambda expressions assigned to the corresponding functional interface class
Way 2 is the lambda expressions as a parameter to method directly to the
Although there is no use new, but every lamba expression will be the compiler to generate a new corresponding functional interface instance

Is way is to rewrite the method of the interface, and then new an implementation class object, the object method incoming parameters,
Way is to change the parameters to 2 lambda form to method

CodePudding user response:

Their difference is not in a lambda, but in the way it is assigned to a variable, two is as a parameter
  • Related