I'm studying for the OCP Java17 exam, and I'm confused about a
test question in "OCP
Java SE 17 Developer Practice Tests: Exam 1Z0-829".
synchronized int step() { return count++; }
. . .
new
Thread(() -˃ waltz.step())
I verified that Thread does not have a constructor which takes a Callable param. The step() method has a return value, so is not a valid Runnable (which can be passed as a param to Thread's constructor). Why does the above example compile? I opened an
IDE and created my own version of that code, and I was able to compile and run something similar with a lamba calling a method which returns a value.
What am I missing? Why does that compile when step() is a Callable but not a Runnable?
Thanks in advance for your help :-)