I am just curious on how people solve this. I often write the same type of code all the time. For instance:
new Thread() {
//...
//...
//...
//Change
In the case of a Thread, you can pass any object that implements Runnable to its constructor.
So, the solution is to create your own class:
public class MyClass implements Runnable {
void run() {
// change this line
}
}
Unfortunately, run isn't static, so you'll have to create an instance of MyClass first:
new Thread(new MyClass()).start();
You could also add variables to MyClass and a constructor so you can pass arguments to it.
Edit: If you need more than just the start method, you can also subclass Thread itself.