R said:
Hello everybody.
As a newbie I have a very simple question.
Can a thread return a non void value? (run method is void...)
e.g. an Object (LinedList, String[][]) ?
The run() method is void, and cannot return anything.
Even if it could, how would the caller know what to do
with it? Note that the caller of run() is not your code,
but something inside the JVM.
All is not lost, though. Remember, you get to write
the class that implements Runnable or extends Thread, and
you can endow this class with any methods and fields you
choose. Furthermore, objects of your class will not vanish
simply because their threads finish executing; they're just
like any other objects and will continue to exist as long
as you have references to them. So if your object computes
a "final answer," you can call your object's methods to
retrieve that answer after the thread finishes. Provided
you synchronize properly, you can even retrieve "preliminary
answers" while the thread is still running.