From 03123b0133bf4ccaa19f8b9bf372f16122b2ea17 Mon Sep 17 00:00:00 2001 From: danthe1st Date: Fri, 28 Jun 2024 18:43:54 +0200 Subject: [PATCH 1/3] update enums article --- .../04_classes_objects/01_enums.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/pages/learn/01_tutorial/03_getting-to-know-the-language/04_classes_objects/01_enums.md b/app/pages/learn/01_tutorial/03_getting-to-know-the-language/04_classes_objects/01_enums.md index 651a2ea..42d7591 100644 --- a/app/pages/learn/01_tutorial/03_getting-to-know-the-language/04_classes_objects/01_enums.md +++ b/app/pages/learn/01_tutorial/03_getting-to-know-the-language/04_classes_objects/01_enums.md @@ -17,7 +17,7 @@ toc: - Precautions {precautions} - Conclusion {conclusion} description: "Working with enums." -last_update: 2023-09-29 +last_update: 2024-06-28 author: ["DanielSchmid"] ---   @@ -32,7 +32,7 @@ No instances of the enum can be created outside of enum constants. ```java public enum DayOfWeek { - // enum constant are listed here: + // enum constants are listed here: MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY } ``` @@ -74,8 +74,8 @@ switch (someDay) { With [Switch Expressions](id:lang.classes-objects.switch-expression), the compiler can check whether all values of the enum are handled. If any possible value is missing in a switch expression, there will be a compiler error. -This is referred to as Exhaustiveness and can also be achieved with regular classes -through [Sealed Classes](https://openjdk.org/jeps/409). +This is referred to as exhaustiveness checking and can also be achieved with regular classes +through [Sealed Classes](https://openjdk.org/jeps/409) and [Patternmatching](/learn/pattern-matching/#switch). ```java DayOfWeek someDay = DayOfWeek.FRIDAY; @@ -99,7 +99,8 @@ Arguments to the constructor are passed in parenthesis after the declaration of ```java public enum DayOfWeek { - MONDAY("MON"), TUESDAY("TUE"), WEDNESDAY("WED"), THURSDAY("THU"), FRIDAY("FRI"), SATURDAY("SAT"), SUNDAY("SUN"); + MONDAY("MON"), TUESDAY("TUE"), WEDNESDAY("WED"), THURSDAY("THU"), FRIDAY("FRI"), + SATURDAY("SAT"), SUNDAY("SUN"); private final String abbreviation; @@ -140,9 +141,9 @@ This allows for comparing instances of enums as well as sorting or searching. ```java public void compareDayOfWeek(DayOfWeek dayOfWeek){ int comparison = dayOfWeek.compareTo(DayOfWeek.WEDNESDAY); - if ( comparison < 0) { + if (comparison < 0) { System.out.println("It's before the middle of the work week."); - } else if(comparison > 0){ + } else if (comparison > 0) { System.out.println("It's after the middle of the work week."); } else { System.out.println("It's the middle of the work week."); @@ -210,6 +211,6 @@ and reading these configuration files in the program in cases like this.   ## Conclusion -Enums provide a simple and safe way of representing a fixed set of constants while keeping most of the flexibilities of classes. They are a special type of class that can be used to write code that is elegant, readable, and maintainable, and work well with other newer modern features like [Switch Expressions](id:lang.classes-objects.switch-expression). Another special class is the Record class introduced in Java 19. Visit our [Records tutorial](id:lang.records) to learn more. +Enums provide a simple and safe way of representing a fixed set of constants while keeping most of the flexibilities of classes. They are a special type of class that can be used to write code that is elegant, readable, maintainable and works well with other modern Java features like [Switch Expressions](id:lang.classes-objects.switch-expression). Another special class is the Record class introduced in Java 19. Visit our [Records tutorial](id:lang.records) to learn more. To learn more about enums, visit the [`java.lang.Enum`](javadoc:Enum) javadoc. \ No newline at end of file From ac01cc32ae484053e11314de2b79103595e3b591 Mon Sep 17 00:00:00 2001 From: danthe1st Date: Mon, 8 Jul 2024 20:28:19 +0200 Subject: [PATCH 2/3] address review comments --- .../04_classes_objects/01_enums.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/pages/learn/01_tutorial/03_getting-to-know-the-language/04_classes_objects/01_enums.md b/app/pages/learn/01_tutorial/03_getting-to-know-the-language/04_classes_objects/01_enums.md index 42d7591..3704c74 100644 --- a/app/pages/learn/01_tutorial/03_getting-to-know-the-language/04_classes_objects/01_enums.md +++ b/app/pages/learn/01_tutorial/03_getting-to-know-the-language/04_classes_objects/01_enums.md @@ -17,7 +17,7 @@ toc: - Precautions {precautions} - Conclusion {conclusion} description: "Working with enums." -last_update: 2024-06-28 +last_update: 2024-07-08 author: ["DanielSchmid"] ---   @@ -71,11 +71,11 @@ switch (someDay) { } ``` -With [Switch Expressions](id:lang.classes-objects.switch-expression), +With [switch expressions](id:lang.classes-objects.switch-expression), the compiler can check whether all values of the enum are handled. If any possible value is missing in a switch expression, there will be a compiler error. This is referred to as exhaustiveness checking and can also be achieved with regular classes -through [Sealed Classes](https://openjdk.org/jeps/409) and [Patternmatching](/learn/pattern-matching/#switch). +through [sealed classes](https://openjdk.org/jeps/409) and [patternmatching](/learn/pattern-matching/#switch). ```java DayOfWeek someDay = DayOfWeek.FRIDAY; From 0557e2f00c55306d8ad13f2494d4353db0787c46 Mon Sep 17 00:00:00 2001 From: danthe1st Date: Mon, 8 Jul 2024 21:21:11 +0200 Subject: [PATCH 3/3] add missing space --- .../04_classes_objects/01_enums.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/pages/learn/01_tutorial/03_getting-to-know-the-language/04_classes_objects/01_enums.md b/app/pages/learn/01_tutorial/03_getting-to-know-the-language/04_classes_objects/01_enums.md index 3704c74..88a6381 100644 --- a/app/pages/learn/01_tutorial/03_getting-to-know-the-language/04_classes_objects/01_enums.md +++ b/app/pages/learn/01_tutorial/03_getting-to-know-the-language/04_classes_objects/01_enums.md @@ -75,7 +75,7 @@ With [switch expressions](id:lang.classes-objects.switch-expression), the compiler can check whether all values of the enum are handled. If any possible value is missing in a switch expression, there will be a compiler error. This is referred to as exhaustiveness checking and can also be achieved with regular classes -through [sealed classes](https://openjdk.org/jeps/409) and [patternmatching](/learn/pattern-matching/#switch). +through [sealed classes](https://openjdk.org/jeps/409) and [pattern matching](/learn/pattern-matching/#switch). ```java DayOfWeek someDay = DayOfWeek.FRIDAY;