|
|
|
|
|
by joshka
1353 days ago
|
|
Another option is any classless java file is just a class with the same name as the file implementing Runnable. E.g. Foo.java println("foo")
Becomes: class Foo implements Runnable {
void run() {
System.out.println("foo");
}
}
Then running java Foo.java instead just stubs a main() that looks like: class Main {
void main() {
new Foo().run();
}
}
|
|
Instead of stubbornly implementing Runnable from those flat files, mix in the well-established concept of single-function-interfaces (Runnable is just one of many) and introduce a top-level "extends" that makes the file body an SFI implementation:
(and it only gets better if you also add the rule "in absence of any imports statements, an implicit import java.lang.*; is added)