Home > Back-end >  Could you tell me how to use the anonymous class lambda expressions to rewrite?
Could you tell me how to use the anonymous class lambda expressions to rewrite?

Time:10-22

I only know that interface can be rewritten so that how to use the lambda expressions of change?
 
Class A {
Public void (a) {
System. The out. Println (" hi ");
}
}
Public class Test {
Public static void main (String [] args) {
A hello=new A () {
Public void (a) {
System. Out.println (" Hello!" );
}
};
Hello. (a);
}
}

CodePudding user response:

What this class is so easy to transform, you again with no flow

CodePudding user response:

reference 1st floor KeepSayingNo response:
what this class is so simple to transform, you again in less than flow

Is a exercises... But don't know how to change the subclass

CodePudding user response:

Lambda is functional interface, A is A class class, you can't rewrite, if you are A is an interface, and there is only one method is not A ()
 
Interface A {
Void (a);
}

So that you can rewrite into using lambda
 
A=A () - & gt; System. Out.println (" Hello!" );
  • Related