How to make this method return an array?

advertisements

How can I make the following method return a character array ?

public char[] startThread() {
    // arr declaration
    Runnable r = new Runnable() {
        @Override
        public void run() {
            arr = getArray(); // arr assignment
        }
    };
    new Thread(r).start();
    return arr;
}

char arrNew[] = startThread();

Note : The above snippet generates an error


Look for java.util.concurrent.Callable, its similar to runnable but returns a value.

http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/Callable.html

or

If in 1.6 JDK, you can look for Future objects.