Lets say you have a class MyClass that has a constructor
public Myclass(SomeObject o)
Myclass, additionally has a method public void doSomethingCleverWith(String s)
I’d like for MyClass to be executed as a Thread, so I
Thread t = new Thread(new MyClass(SomeObject));
When executing this thread, however run, will need to call doSomethingCleverWith(String). run, however (as i understand it) does not take in any parameters.
How would you recommend i handle this? Should String s be a part of a MyClass‘s constructor? Can i somehow do something else?
You don’t execute an object on a thread – you execute code on a thread… the code specified by the
run()method of the runnable that you pass in to theThreadconstructor, assuming you’re doing it that way.It’s not really clear what you’re trying to do, but it sounds like you probably need to pass the extra information (the string) to the constructor of
MyClass… or execute it in a different way, such as:If you clarify what you’re trying to achieve, we may be able to help you more.