Records
Records are immutable data classes used in Java to encapsulate "packets" of data.
Records make it much easier to implement these kinds of "wrapper classes"
without having to define constructors, toString()
, getters, etc., every single
time.
Example code
public record Car(String engine, String brand) {
public String brandAsLowerCase() {
return brand().toLowerCase();
}
}
This, automatically, also creates getters String engine()
and String brand()
on Car
objects.
You can create an instance of a Record just like with any other class:
var car = new Car("my engine", "Porsche");
System.out.println(car.engine());
JsonMessage
One area where the Telestion ecosystem uses records is for JSON object Event Bus messages. This adds type safety around event bus messages and thus makes them easier to handle.
Learn how to use the Record-basedJsonMessage
for Event Bus Messages »/application/tutorials/using-jsonmessage/TelestionConfiguration
Another area where Records are useful within the Telestion ecosystem is Verticle configuration.
Learn how to use Records extendingTelestionConfiguration
to make your Verticles configurable »/application/tutorials/adding-configuration-options/