I'm trying out the new records feature with java 14, currently in preview.
I know that in Java one has to have exactly one public class per file but with the new record syntax being so nice and short it just seem wasteful to have a bunch of files each with a single line of code in them.
In particular I wanted to try to model a simple AST like this, and I think that having everything together in one file really improves readability and comprehension.
package com.company;
public interface Expression {
}
public record IntExp(int value) implements Expression {
}
public record AddExp(Expression left, Expression right) implements Expression {
}
public record SubtractExp(Expression left, Expression right) implements Expression {
}
// Etc..
But unfortunately this will not compile.
So my question is:
Is there any way around this limitation or some way to keep code like this all in one place?