Playing with Java Records (JEP 395) 📎
Link
Java 16 Record:
public record Link(String text, String uri) {
public Link {
uri = "https://" + uri;
}
public String toHTMLLink() {
return """
<a href="%s">%s</a>""".formatted(this.uri,this.text);
}
public static String exampleURI() {
return "https://airhacks.live";
}
}
...and testing:
public class RecordTest {
@Test
public void rocks() {
var link = new Link("workshops", "airhacks.live");
System.out.println(link);
System.out.println(link.text() + " - " + link.uri());
System.out.println(Link.exampleURI());
System.out.println("show me the link; " + link.toHTMLLink());
}
}
..."from scratch":