Skip to content

Commit a4c644f

Browse files
committed
* Java 19.
* Remove lombok dependency for bug using lates versions of java fix typos caused by this. * Add README.md for java 19. * Show-case record pattern.
1 parent ee336f4 commit a4c644f

File tree

7 files changed

+120
-37
lines changed

7 files changed

+120
-37
lines changed

build.gradle

+19-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,32 @@ plugins {
33
id 'io.spring.dependency-management' version '1.0.1.RELEASE'
44
}
55

6-
group 'org.example'
6+
java {
7+
toolchain {
8+
languageVersion = JavaLanguageVersion.of(21) // Ensure you're targeting the correct Java version
9+
}
10+
}
11+
12+
group 'java.examples'
713
version '1.0-SNAPSHOT'
814

915
repositories {
1016
mavenCentral()
1117
}
1218

1319
dependencies {
14-
implementation 'org.projectlombok:lombok:1.18.22'
1520
implementation 'org.json:json:20231013'
16-
annotationProcessor 'org.projectlombok:lombok:1.18.22'
21+
}
22+
23+
tasks.withType(JavaCompile) {
24+
options.compilerArgs += ['--enable-preview']
25+
}
26+
27+
tasks.withType(Test) {
28+
jvmArgs += '--enable-preview'
29+
}
30+
31+
tasks.withType(JavaExec) {
32+
jvmArgs += '--enable-preview'
1733
}
1834

src/main/java/domain/Customer.java

-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package domain;
22

3-
import lombok.Builder;
4-
import lombok.Data;
5-
6-
@Builder
7-
@Data
83
public class Customer {
94

105
private long id;

src/main/java/domain/Order.java

-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package domain;
22

3-
import lombok.Data;
43

54
import java.time.LocalDate;
65
import java.util.List;
76

8-
@Data
97
public class Order {
108

119
private long id;

src/main/java/domain/Product.java

-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package domain;
22

33

4-
import lombok.Data;
5-
64
import java.util.Date;
75
import java.util.List;
86

9-
@Data
107
public class Product {
118

129
private String id;

src/main/java/domain/User.java

+60-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
package domain;
22

3-
import lombok.AllArgsConstructor;
4-
import lombok.Builder;
5-
import lombok.Data;
6-
import lombok.NoArgsConstructor;
73

84
import java.time.LocalDate;
95
import java.util.List;
106
import java.util.Optional;
117

128
import static java.util.Arrays.asList;
139

14-
@Data
15-
@Builder
16-
@NoArgsConstructor
17-
@AllArgsConstructor
1810
public class User {
1911

2012
private static final int THRESHOLD_ADULT = 18;
@@ -27,6 +19,9 @@ public class User {
2719
private String phoneNumber;
2820
private LocalDate dateOfBirth;
2921

22+
public User() {
23+
}
24+
3025
public User(String name) {
3126
this.name = name;
3227
}
@@ -38,6 +33,10 @@ public User(int age, String name, String lastName, Gender gender) {
3833
this.gender = gender;
3934
}
4035

36+
public boolean isAdult(User u) {
37+
return u.age >= THRESHOLD_ADULT;
38+
}
39+
4140
public static boolean isValidUser(User user) {
4241
return !user.name.equals(user.lastName);
4342
}
@@ -58,19 +57,62 @@ public static List<User> defaultList() {
5857
}
5958

6059
public static User getAnExampleUser() {
60+
return new User(27, "Jhon","", Gender.MALE);
61+
}
62+
63+
public int getAge() {
64+
return age;
65+
}
66+
67+
public void setAge(int age) {
68+
this.age = age;
69+
}
70+
71+
public String getName() {
72+
return name;
73+
}
74+
75+
public void setName(String name) {
76+
this.name = name;
77+
}
78+
79+
public String getLastName() {
80+
return lastName;
81+
}
82+
83+
public void setLastName(String lastName) {
84+
this.lastName = lastName;
85+
}
86+
87+
public Optional<String> getEmail() {
88+
return email;
89+
}
90+
91+
public void setEmail(Optional<String> email) {
92+
this.email = email;
93+
}
6194

62-
return User.builder()
63-
.name("Jhon")
64-
.lastName("Lotero")
65-
.phoneNumber("123456789")
66-
.dateOfBirth(LocalDate.of(1990, 11, 16))
67-
.email(Optional.of("[email protected]"))
68-
.gender(Gender.MALE)
69-
.build();
95+
public Gender getGender() {
96+
return gender;
7097
}
7198

72-
public boolean isAdult(User user) {
73-
return user.age >= THRESHOLD_ADULT;
99+
public void setGender(Gender gender) {
100+
this.gender = gender;
101+
}
102+
103+
public String getPhoneNumber() {
104+
return phoneNumber;
105+
}
106+
107+
public void setPhoneNumber(String phoneNumber) {
108+
this.phoneNumber = phoneNumber;
109+
}
110+
111+
public LocalDate getDateOfBirth() {
112+
return dateOfBirth;
74113
}
75114

115+
public void setDateOfBirth(LocalDate dateOfBirth) {
116+
this.dateOfBirth = dateOfBirth;
117+
}
76118
}

src/main/java/features_versions/nineteen_19/README.md

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
# Java 19
22

3+
## Preview Features:
34

4-
## Features
5+
Record Patterns (JEP 405): Enables deconstructing record values using patterns for clearer and more concise code.
6+
Virtual Threads (JEP 425): Provides a lightweight threading implementation for high-throughput concurrent applications.
7+
Foreign Function & Memory API (JEP 424): Allows Java programs to interoperate with code and data outside the Java runtime, improving performance and flexibility.
8+
Pattern Matching for switch (JEP 427): Extends the switch statement with pattern matching capabilities for more readable and powerful conditional statements (third preview).
9+
10+
## Incubator Features:
11+
12+
Vector API (JEP 426): Offers an API for vector computation utilizing modern SIMD instructions for improved performance in numerical applications (fourth incubator).
13+
Structured Concurrency (JEP 428): Introduces an experimental API for managing asynchronous tasks with less boilerplate code (incubator).
14+
Other Notable Changes:
15+
16+
Deprecation of Locale class constructors: Encourages the use of static factory methods for creating Locale objects.
17+
Automatic Generation of the CDS Archive: Improves class loading performance by automatically generating the CDS archive during installation.
18+
Linux/RISC-V Port (JEP 422): Provides an official Java port for the RISC-V architecture.
519

6-
- **New System Properties for System.out and System.err**: Enhanced system logging.
7-
- **Additional Date-Time Formats**: More options for date-time formatting.
8-
- **New Methods for Preallocated HashMaps and HashSets**: Improving collection initialization.
9-
- **Windows KeyStore Updates**: Enhanced security features.
10-
- **Support for Unicode 14.0**: Updated Unicode support.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package features_versions.nineteen_19.base;
2+
3+
public class RecordPattern {
4+
5+
public static void main(String[] args) {
6+
printSumBefore19(new Point(1, 2));
7+
printSumNew19(new Point(1, 2));
8+
}
9+
10+
record Point(int x, int y) { }
11+
12+
static void printSumBefore19(Object o) {
13+
if (o instanceof Point p) {
14+
int x = p.x(); // get x()
15+
int y = p.y(); // get y()
16+
System.out.println(x + y);
17+
}
18+
}
19+
20+
static void printSumNew19(Object o) {
21+
if (o instanceof Point(int x,int y)) { // record pattern
22+
System.out.println(x + y); // access x and y directly
23+
}
24+
}
25+
26+
}

0 commit comments

Comments
 (0)