by joshka · 4y ago · 0 comments
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:
extends java.lang.Runnable;
java.lang.System.out.println("Hello world");
(and it only gets better if you also add the rule "in absence of any imports statements, an implicit import java.lang.*; is added)BTW, I think the pedantic view on this based on the (mailing list discussion) is that it becomes java.lang.StaticImports.println("Hello"), which calls System.out.println.
1. Single file single function imperative
2. Single file multi-function imperative (introduce multiple functions)
3. OO (introduce classes etc)