Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

12 Commits

Repository files navigation

java-14

Yeah baby!

prepare

For now, use IntelliJ IDEA 2020 EAP with jdk 14 installed!

# sdk ls java# sdk install java 14.ea.36-open
sdk use java 14.ea.36-open

maven

<plugins>
<!-- mvn comopile -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>14</release>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<parameters>true</parameters>
</configuration>
</plugin>
<!-- mvn test -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
</plugins>

records

wrong

previously we usually used something like lombok to acheive case (scala) or data (kotlin) classes functionality in java:

@Data@NoArgsConstructor@AllArgsConstructorclassPerson {
privateLongid;
privateStringname;
}

correct

but with java 14 we finally have it out of the box!

recordPerson(Longid, Stringname) {}

usage

varp = newPerson(1L, "Max");
varid = p.id();
varname = p.name();
System.out.printf("%s is person with id %d and name %s!%n", p, id, name);
// output: Person[id=1, name=Max] is person with id 1 and name Max!

compact constructor

recordPerson(Longid, Stringname) {
Person {
Assert.isTrue(this.id > 0, "id must be greater than zero.");
this.name = this.name.toLowerCase();
}
}

resources

other repos

About

Yeah baby!

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors