Update formatting

This commit is contained in:
Michael Pratt 2020-11-20 07:49:50 -07:00
parent 4164ff6a03
commit 567a63cb7d
5 changed files with 12 additions and 22 deletions

View File

@ -51,8 +51,8 @@
<configuration> <configuration>
<release>${maven.compiler.release}</release> <release>${maven.compiler.release}</release>
<compilerArgs>--enable-preview</compilerArgs> <compilerArgs>--enable-preview</compilerArgs>
<source>15</source> <source>14</source>
<target>15</target> <target>14</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -3,15 +3,12 @@ package com.baeldung.whatsnew.records;
/** /**
* Java record with a header indicating 2 fields. * Java record with a header indicating 2 fields.
*/ */
public record Person(String name, int age) public record Person(String name, int age) {
{
/** /**
* Public constructor that does some basic validation. * Public constructor that does some basic validation.
*/ */
public Person public Person {
{ if (age < 0) {
if (age < 0)
{
throw new IllegalArgumentException("Age cannot be negative"); throw new IllegalArgumentException("Age cannot be negative");
} }
} }

View File

@ -2,10 +2,8 @@ package com.baeldung.whatsnew.sealedclasses;
import java.util.Date; import java.util.Date;
public non-sealed class Employee extends Person public non-sealed class Employee extends Person {
{ public Date getHiredDate() {
public Date getHiredDate()
{
return new Date(); return new Date();
} }
} }

View File

@ -1,5 +1,4 @@
package com.baeldung.whatsnew.sealedclasses; package com.baeldung.whatsnew.sealedclasses;
public final class Manager extends Person public final class Manager extends Person {
{
} }

View File

@ -2,23 +2,19 @@ package com.baeldung.whatsnew.sealedclasses;
import java.util.Date; import java.util.Date;
public sealed class Person permits Employee, Manager public sealed class Person permits Employee, Manager {
{
/** /**
* Demonstration of pattern matching for instanceof * Demonstration of pattern matching for instanceof
* *
* @param person A Person object * @param person A Person object
* @return * @return
*/ */
public static void patternMatchingDemo(Person person) public static void patternMatchingDemo(Person person) {
{ if(person instanceof Employee employee) {
if(person instanceof Employee employee)
{
Date hiredDate = employee.getHiredDate(); Date hiredDate = employee.getHiredDate();
} }
if(person instanceof Employee employee && employee.getHiredDate() != null) if(person instanceof Employee employee && employee.getHiredDate() != null) {
{
Date hiredDate = employee.getHiredDate(); Date hiredDate = employee.getHiredDate();
} }
} }