Page 1 of 1

About Question enthuware.ocpjp.v11.2.3318 :

Posted: Sat Feb 04, 2023 3:55 am
by asi-aal
The last option is a bit confusing


Runnable r = ()-> 1+2; would not compile but someMethod() (which returns an int) compiles? How could you explain this?

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

Posted: Sat Feb 04, 2023 8:10 am
by admin
1+2 is a syntactically illegal statement, while a method call is not.
Please go through this article carefully to understand how a lambda expression is perceived by the compiler:
https://enthuware.com/oca-ocp-java-cert ... interfaces