Skip to content

Commit 10a9c8a

Browse files
committed
JEP 455: Primitive Types in Patterns, instanceof, and switch
1 parent 1658c17 commit 10a9c8a

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This repository contains Java examples that are designed to track and document t
1212
* [Java 23](java-23/) (September, 2024)
1313
* [JEP 477](java-23/src/main/java/com/ibrahimatay/JEP477ImplicitlyDeclaredClassesAndInstanceMainMethods.java): Implicitly Declared Classes and Instance Main Methods
1414
* [JEP 467](java-23/src/main/java/com/ibrahimatay/JEP467MarkdownDocumentationComments.java): Markdown Documentation Comments
15+
* [JEP 455](java-23/src/main/java/com/ibrahimatay/JEP455PrimitiveTypesInPatternsInstanceofAndSwitch.java): Primitive Types in Patterns, instanceof, and switch]
1516

1617
* [Java 22](java-22/) (March, 2024)
1718
* [JEP 458](java-22/src/main/java/com/ibrahimatay/JEP458LaunchMultiFileSourceCode.java): Launch Multi-File Source-Code Programs
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.ibrahimatay;
2+
3+
public class JEP455PrimitiveTypesInPatternsInstanceofAndSwitch {
4+
// JEP 455: Primitive Types in Patterns, instanceof, and switch
5+
// https://openjdk.org/jeps/455
6+
7+
public static void main(String[] args) {
8+
System.out.printf("%1$s HTTP status code refers to a %2$s%n", 100, getHTTPCodeDesc(100));
9+
System.out.printf("%1$s HTTP status code refers to a %2$s%n", 200, getHTTPCodeDesc(200));
10+
System.out.printf("%1$s HTTP status code refers to a %2$s%n", 403, getHTTPCodeDesc(403));
11+
System.out.printf("%1$s HTTP status code refers to a %2$s%n", 0, getHTTPCodeDesc(0));
12+
13+
// 100 HTTP status code refers to a Continue
14+
// 200 HTTP status code refers to a OK
15+
// 403 HTTP status code refers to a Client Error
16+
// 0 HTTP status code refers to a Unknown error
17+
}
18+
19+
public static String getHTTPCodeDesc(int code) {
20+
return switch(code) {
21+
case 100 -> "Continue";
22+
case 200 -> "OK";
23+
case 301 -> "Moved Permanently";
24+
case 302 -> "Found";
25+
case 400 -> "Bad Request";
26+
case 500 -> "Internal Server Error";
27+
case 502 -> "Bad Gateway";
28+
case int i when i > 100 && i < 200 -> "Informational";
29+
case int i when i > 200 && i < 300 -> "Successful";
30+
case int i when i > 302 && i < 400 -> "Redirection";
31+
case int i when i > 400 && i < 500 -> "Client Error";
32+
case int i when i > 502 && i < 600 -> "Server Error";
33+
default -> "Unknown error";
34+
};
35+
}
36+
}

java-23/src/main/java/com/ibrahimatay/Main.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)