Page 1 of 1

About Question enthuware.ocpjp.v11.2.3641 :

Posted: Fri May 03, 2024 6:48 am
by adrianjara
Hello

I know it's not within the context of the question, but I wanted to write to find out if I'm wrong or not.

In the following code, it appears that the lambda expression is typed incorrectly, is this correct?

Code: Select all

public void invokeService(String srvname, String host, int port){
     ...
     Socket socket = null;
     try{
        AccessController.doPrivileged( ( PrivilegedExceptionAction<Void> ) ()->
               socket = new Socket(host, port);
               return null;
     }
     ...
}
Both lines after the lamda expression belong to the lamda expression? So shouldn't I have a key?

And if this were not the case, if only the first line belongs to the lambda, which I do not think is the case, then the ; at the end of the expression it would not be bad.

Thanks in advance for responding

Re: About Question enthuware.ocpjp.v11.2.3641 :

Posted: Fri May 03, 2024 7:28 am
by admin
Yes, an opening and closing brace should be there so that both the line become part of the lambda.

>Both lines after the lamda expression belong to the lamda expression?
Yes.

>So shouldn't I have a key?
Not sure what you mean.