{"id":342563,"date":"2023-04-14T03:44:34","date_gmt":"2023-04-14T02:44:34","guid":{"rendered":"https:\/\/blog.jetbrains.com\/idea\/2023\/03\/java-20-and-intellij-idea\/"},"modified":"2023-04-14T03:44:39","modified_gmt":"2023-04-14T02:44:39","slug":"java-20-and-intellij-idea","status":"publish","type":"idea","link":"https:\/\/blog.jetbrains.com\/ja\/idea\/2023\/04\/java-20-and-intellij-idea\/","title":{"rendered":"Java 20 \u3068 IntelliJ IDEA"},"content":{"rendered":"<p>\u79c1\u306f\u9577\u3089\u304f Java \u306e\u65b0\u30ea\u30ea\u30fc\u30b9\u306b\u3064\u3044\u3066\u57f7\u7b46\u3057\u3066\u304d\u307e\u3057\u305f\u304c\uff08Java 10 \u4ee5\u964d\uff09\u3001\u958b\u767a\u8005\u304c 6 \u304b\u6708\u3054\u3068\u306bJava \u306e\u65b0\u6a5f\u80fd\u306b\u3064\u3044\u3066\u77e5\u308a\u3001\u4f7f\u7528\u3067\u304d\u308b\u3068\u3044\u3046\u306e\u306f\u7d20\u6674\u3089\u3057\u3044\u3053\u3068\u3060\u3068\u601d\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u904e\u53bb\u306e\u30ea\u30ea\u30fc\u30b9\u3068\u6bd4\u3079\u308b\u3068\u3001Java 20 \u306b\u8ffd\u52a0\u3055\u308c\u305f\u6a5f\u80fd\u306f\u305d\u308c\u307b\u3069\u591a\u304f\u306f\u3042\u308a\u307e\u305b\u3093\u3002 Java 20 \u3067\u306f\u30b9\u30ec\u30c3\u30c9\u5185\u3084\u30b9\u30ec\u30c3\u30c9\u9593\u3067\u306e\u30a4\u30df\u30e5\u30fc\u30bf\u30d6\u30eb\u30c7\u30fc\u30bf\u306e\u5171\u6709\u3092\u53ef\u80fd\u306b\u3057\u3066\u4eee\u60f3\u30b9\u30ec\u30c3\u30c9\u3092\u30b5\u30dd\u30fc\u30c8\u3059\u308b <a href=\"https:\/\/openjdk.org\/jeps\/429\" target=\"_blank\" rel=\"noopener\">Scoped Values<\/a> \u304c<a href=\"https:\/\/openjdk.org\/jeps\/11\" target=\"_blank\" rel=\"noopener\">\u30a4\u30f3\u30ad\u30e5\u30d9\u30fc\u30c8 API<\/a> \u3068\u3057\u3066\u5c0e\u5165\u3055\u308c\u3066\u3044\u307e\u3059\u3002 2 \u56de\u76ee\u306e\u30d7\u30ec\u30d3\u30e5\u30fc\u3092\u958b\u59cb\u3057\u305f<a href=\"https:\/\/openjdk.org\/jeps\/432\" target=\"_blank\" rel=\"noopener\">\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3<\/a>\u3067\u306f\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u306e\u30b5\u30dd\u30fc\u30c8\u304c\u6539\u5584\u3055\u308c\u3001\u62e1\u5f35 for \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3067\u306e\u4f7f\u7528\u304c\u53ef\u80fd\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002 4 \u56de\u76ee\u306e\u30d7\u30ec\u30d3\u30e5\u30fc\u3092\u958b\u59cb\u3057\u305f <a href=\"https:\/\/openjdk.org\/jeps\/433\" target=\"_blank\" rel=\"noopener\">switch \u306e\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u30f3\u30b0<\/a>\u3067\u306f\u3001\u7db2\u7f85\u7684\u306a switch\u3001\u5358\u7d14\u306a switch \u30e9\u30d9\u30eb\u3001\u304a\u3088\u3073\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u306e\u63a8\u8ad6\u3055\u308c\u308b\u578b\u5f15\u6570\u3092\u64cd\u4f5c\u3059\u308b\u969b\u306e\u4f7f\u3044\u52dd\u624b\u304c\u6539\u5584\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>Java 20 \u3067 2 \u56de\u76ee\u306e\u30d7\u30ec\u30d3\u30e5\u30fc\u3068\u306a\u308b <a href=\"https:\/\/openjdk.org\/jeps\/434\" target=\"_blank\" rel=\"noopener\">Foreign Function and Memory API<\/a> \u3067\u306f\u3001Java \u30b3\u30fc\u30c9\u3068 JVM \u5916\u90e8\u306e\u30b3\u30fc\u30c9\u3068\u30c7\u30fc\u30bf\u306e\u901a\u4fe1\u3092\u53ef\u80fd\u306b\u3059\u308b\u6a5f\u80fd\u304c\u5f15\u304d\u7d9a\u304d\u6539\u5584\u3055\u308c\u3066\u3044\u307e\u3059\u3002 <a href=\"https:\/\/openjdk.org\/jeps\/437\" target=\"_blank\" rel=\"noopener\">\u69cb\u9020\u5316\u3055\u308c\u305f\u4e26\u884c\u6027<\/a>\u306b\u3088\u3063\u3066\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3001\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u4f5c\u6210\u306b\u9769\u547d\u3092\u3082\u305f\u3089\u3059\u8efd\u91cf\u306e<a href=\"https:\/\/openjdk.org\/jeps\/436\" target=\"_blank\" rel=\"noopener\">\u4eee\u60f3\u30b9\u30ec\u30c3\u30c9<\/a>\u304c\u6700\u65b0\u306e Java \u30ea\u30ea\u30fc\u30b9\u3067\u3082\u3046\u4e00\u5ea6\u30d7\u30ec\u30d3\u30e5\u30fc\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002 \u4eca\u56de\u3067 5 \u56de\u76ee\u306e\u30d7\u30ec\u30d3\u30e5\u30fc\u3092\u958b\u59cb\u3057\u305f <a href=\"https:\/\/openjdk.org\/jeps\/438\" target=\"_blank\" rel=\"noopener\">Vector API<\/a> \u306b\u3088\u308a\u3001\u30b3\u30fc\u30c9\u306e\u30d9\u30af\u30c8\u30eb\u6f14\u7b97\u304c\u64cd\u4f5c\u3057\u3084\u3059\u304f\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30d6\u30ed\u30b0\u8a18\u4e8b\u3067\u306f\u3001\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u3001\u7db2\u7f85\u7684\u306a switch \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3001\u304a\u3088\u3073\u5f0f\u306e\u578b\u63a8\u8ad6\u3084\u62e1\u5f35 <code>for<\/code> \u30d8\u30c3\u30c0\u30fc\u3067\u306e\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u3068\u3044\u3063\u305f\u6700\u3082\u91cd\u8981\u306a\u5909\u66f4\u70b9\u3092\u4e2d\u5fc3\u306b\u3001IntelliJ IDEA \u306b\u3088\u308b\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u3068 switch \u7528\u306e\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u30f3\u30b0\u306a\u3069\u306e\u8a00\u8a9e\u6a5f\u80fd\u306e\u30b5\u30dd\u30fc\u30c8\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u59cb\u3081\u307e\u3057\u3087\u3046\u3002<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2023\/03\/Blog_Featured_image_1280x600-10.png\" alt=\"\" \/><\/figure>\n<h2>IntelliJ IDEA \u306e\u69cb\u6210<\/h2>\n<p>Java 20 \u306e\u30b5\u30dd\u30fc\u30c8\u306f IntelliJ IDEA2023.1 \u3067\u63d0\u4f9b\u3055\u308c\u3066\u3044\u307e\u3059\u3002 \u4eca\u5f8c\u306e IntelliJ IDEA \u30ea\u30ea\u30fc\u30b9\u3067\u306f\u3001\u3055\u3089\u306b\u30b5\u30dd\u30fc\u30c8\u3092\u5145\u5b9f\u3055\u305b\u308b\u4e88\u5b9a\u3067\u3059\u3002<\/p>\n<p>switch \u7528\u306e\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u3084\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u30f3\u30b0\u306a\u3069\u306e Java 20 \u306e\u65b0\u3057\u3044\u8a00\u8a9e\u6a5f\u80fd\u3092\u4f7f\u7528\u3059\u308b\u306b\u306f\u3001<i>ProjectSettings\uff08\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u8a2d\u5b9a\uff09| Project\uff08\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\uff09<\/i>\u306b\u79fb\u52d5\u3057\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e SDK \u3092 20\u3001\u30d7\u30ec\u30b8\u30a7\u30af\u30c8\u306e\u8a00\u8a9e\u30ec\u30d9\u30eb\u3092 <i>\u201920 (Preview) \u2013 Record patterns (second preview), Pattern Matching for switch (fourth preview)\u2019<\/i>\uff0820 (\u30d7\u30ec\u30d3\u30e5\u30fc) &#8211; \u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3 (2 \u56de\u76ee\u306e\u30d7\u30ec\u30d3\u30e5\u30fc)\u3001switch \u306e\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u30f3\u30b0 (4 \u56de\u76ee\u306e\u30d7\u30ec\u30d3\u30e5\u30fc)\uff09\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2023\/03\/1-1.png\" alt=\"\" \/><\/figure>\n<p>\u30b7\u30b9\u30c6\u30e0\u306b\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u6e08\u307f\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306e JDK \u3092\u4f7f\u7528\u3059\u308b\u304b\u3001<i>\u2018Edit\u2019<\/i> \uff08\u7de8\u96c6\uff09\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066 <i>\u2018Add SDK\uff08SDK \u306e\u8ffd\u52a0\uff09 &gt;\u2019<\/i> <i>\u2018Download JDK\u2026\u2019\uff08JDK \u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\uff09<\/i>\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u5225\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 \u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b JDK \u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306f\u3001\u30d9\u30f3\u30c0\u30fc\u306e\u30ea\u30b9\u30c8\u304b\u3089\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<p>Module\uff08\u30e2\u30b8\u30e5\u30fc\u30eb\uff09\u30bf\u30d6\u3067\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u540c\u3058\u8a00\u8a9e\u30ec\u30d9\u30eb\uff08<i>20 (Preview) \u2013 Record patterns (second preview), Pattern Matching for switch (fourth preview)<\/i>\uff09\uff0820 (\u30d7\u30ec\u30d3\u30e5\u30fc) &#8211; \u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3 (2 \u56de\u76ee\u306e\u30d7\u30ec\u30d3\u30e5\u30fc)\u3001switch \u306e\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u30f3\u30b0 (4 \u56de\u76ee\u306e\u30d7\u30ec\u30d3\u30e5\u30fc)\uff09\u304c\u9078\u629e\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2023\/03\/2-1.png\" alt=\"\" \/><\/figure>\n<p>\u3053\u308c\u3092\u9078\u629e\u3059\u308b\u3068\u3001IntelliJ IDEA \u304c\u4eca\u5f8c\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3067 Java \u30d7\u30ec\u30d3\u30e5\u30fc\u306e\u8a00\u8a9e\u6a5f\u80fd\u306e\u30b5\u30dd\u30fc\u30c8\u3092\u4e2d\u6b62\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3053\u3068\u3092\u901a\u77e5\u3059\u308b\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u304c\u7d9a\u3051\u3066\u8868\u793a\u3055\u308c\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002 \u30d7\u30ec\u30d3\u30e5\u30fc\u306e\u6a5f\u80fd\u306f\uff08\u307e\u3060\uff09\u6052\u4e45\u7684\u306b\u63d0\u4f9b\u3055\u308c\u308b\u6a5f\u80fd\u3067\u306f\u306a\u304f\u3001\u4eca\u5f8c\u306e Java \u30ea\u30ea\u30fc\u30b9\u3067\u5909\u66f4\uff08\u307e\u305f\u306f\u524a\u9664\uff09\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3067\u3059\u3002<br \/>\u3067\u306f\u3001Java 19 \u3067\u5c0e\u5165\u3055\u308c\u305f\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u306b\u3064\u3044\u3066\u7c21\u5358\u306b\u304a\u3055\u3089\u3044\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3<\/h2>\n<p>\u30ec\u30b3\u30fc\u30c9\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u5b9f\u884c\u3057\u305f\u3044\u64cd\u4f5c\u3068\u3044\u3048\u3070\u3001\u305d\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u5024\u3092\u62bd\u51fa\u3057\u3066\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5185\u3067\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3057\u3087\u3046\u3002 \u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u306f\u307e\u3055\u306b\u3053\u306e\u64cd\u4f5c\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<p>\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u3068\u306f\u4f55\u304b\u3001\u305d\u3057\u3066\u305d\u308c\u304c\u5fc5\u8981\u306a\u7406\u7531\u306b\u3064\u3044\u3066\u7c21\u5358\u306b\u5fa9\u7fd2\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u306e\u304a\u3055\u3089\u3044<\/h3>\n<p>\u30ec\u30b3\u30fc\u30c9\u306f\u3001\u30c7\u30fc\u30bf\u3092\u900f\u904e\u7684\u306b\u904b\u642c\u3059\u308b\u30ad\u30e3\u30ea\u30a2\u3092\u4f5c\u6210\u3059\u308b\u5358\u7d14\u3067\u660e\u77ad\u306a\u624b\u6cd5\u3067\u3059\u3002 \u30ec\u30b3\u30fc\u30c9\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u8907\u6570\u306e\u5024\uff08\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3068\u3082\u547c\u3070\u308c\u307e\u3059\uff09\u3092\u307e\u3068\u3081\u3066\u96c6\u8a08\u3067\u304d\u307e\u3059\u3002 \u9006\u306b\u3001\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u306f\u30ec\u30b3\u30fc\u30c9\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u5206\u89e3\u3057\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u5024\u3092\u7c21\u5358\u306b\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u305f\u3068\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30ec\u30b3\u30fc\u30c9\u304c\u3042\u308b\u3068\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">record Name       (String fName, String lName) { }\nrecord PhoneNumber(String areaCode, String number) { }\nrecord Country    (String countryCode, String countryName) { }\nrecord Passenger  (Name name,\n                  PhoneNumber phoneNumber,\n                  Country from,\n                  Country destination) { }<\/pre>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u3068 <code>instanceof<\/code> \u6f14\u7b97\u5b50\u3092\u4e00\u7dd2\u306b\u4f7f\u7528\u3057\u3066\u30ec\u30b3\u30fc\u30c9\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u4e00\u9023\u306e\u30d1\u30bf\u30fc\u30f3\u5909\u6570\u306b\u5206\u89e3\u3059\u308b\u660e\u78ba\u306a\u30b3\u30fc\u30c9\u3092\u5b9a\u7fa9\u3059\u308b\u65b9\u6cd5\u3092\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">boolean checkFirstNameAndCountryCodeAgain (Object obj) {\n  if (obj instanceof Passenger(Name (String fName, var lName),\n                               var phoneNumber,\n                               Country from,\n                               Country (var countryCode, String countryName) )) {\n      if (fName != null &amp;&amp; countryCode != null) {\n          return fName.startsWith(\"Simo\") &amp;&amp; countryCode.equals(\"PRG\");\n      }\n  }\n  return false;\n}<\/pre>\n<p>\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u3092\u307e\u3063\u305f\u304f\u77e5\u3089\u306a\u3044\u65b9\u306f\u3001<a href=\"https:\/\/blog.jetbrains.com\/idea\/2022\/11\/java-19-and-intellij-idea\/\">Java 19 and IntelliJ IDEA<\/a> \u3068\u3044\u3046\u79c1\u306e\u30d6\u30ed\u30b0\u8a18\u4e8b\u3092\u8aad\u3080\u3053\u3068\u3092\u304a\u52e7\u3081\u3057\u307e\u3059\u3002\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u81ea\u4f53\u306e\u8aac\u660e\u3068\u4f7f\u7528\u3059\u3079\u304d\u7406\u7531\u3092\u8a73\u3057\u304f\u8aac\u660e\u3057\u3066\u3044\u307e\u3059\u3002 \u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u306e Java 19 \u304b\u3089 Java 20 \u3078\u306e\u5909\u66f4\u70b9\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>Java 20 \u3067\u306f\u3001Java 19 \u3067\u8ffd\u52a0\u3055\u308c\u305f<a href=\"https:\/\/blog.jetbrains.com\/idea\/2022\/11\/java-19-and-intellij-idea\/#NamedRecordPattern\">named Record Patterns<\/a>\uff08\u540d\u524d\u4ed8\u304d\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\uff09\u306e\u4f7f\u7528\u304c\u5ec3\u6b62\u3055\u308c\u307e\u3057\u305f\u3002 Java 20 \u3067\u306f\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u306e\u578b\u5f15\u6570\u306e\u63a8\u8ad6\u306e\u30b5\u30dd\u30fc\u30c8\u304c\u6539\u5584\u3055\u308c\u3001\u62e1\u5f35 <code>for<\/code> \u30eb\u30fc\u30d7\u306e\u30d8\u30c3\u30c0\u30fc\u3067\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>\u30ec\u30b3\u30fc\u30c9\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u578b\u63a8\u8ad6<\/h3>\n<p>Java 19 \u3067\u306f\u30ec\u30b3\u30fc\u30c9\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u63a8\u8ad6\u304c\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3001\u30ec\u30b3\u30fc\u30c9\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u660e\u793a\u7684\u306a\u578b\u3092\u4f7f\u7528\u3059\u308b\u4ee3\u308f\u308a\u306b <code>var<\/code> \u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002 \u524d\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u306b\u3042\u308b\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u306e\u4f8b\u3092\u3082\u3046\u4e00\u5ea6\u78ba\u8a8d\u3057\u3001<code>var<\/code> \u306e\u4f7f\u7528\u7b87\u6240\u306b\u6ce8\u610f\u3057\u3066\u898b\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">boolean checkFirstNameAndCountryCodeAgain (Object obj) {\n  if (obj instanceof Passenger(Name (String fName, var lName),\n                               var phoneNumber,\n                               Country from,\n                               Country (var countryCode, String countryName) )) {\n      if (fName != null &amp;&amp; countryCode != null) {\n          return fName.startsWith(\"Simo\") &amp;&amp; countryCode.equals(\"PRG\");\n      }\n  }\n  return false;\n}<\/pre>\n<p><code>var<\/code> \u3092\u4f7f\u3063\u3066\u5b9a\u7fa9\u3055\u308c\u308b\u3059\u3079\u3066\u306e\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u306b\u9069\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3001IntelliJ IDEA \u306f\u4e88\u7d04\u30ad\u30fc\u30ef\u30fc\u30c9 <code>var<\/code> \u3092\u4f7f\u3063\u3066\u5b9a\u7fa9\u3055\u308c\u305f\u5909\u6570\u306e\u660e\u793a\u7684\u306a\u578b\u3092\u8868\u793a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<figure class=\"wp-block-image alignnone wp-image-16062\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2022\/11\/using-var.gif\" alt=\"\" \/><\/figure>\n<h3>\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3<\/h3>\n<p>Java 20 \u306f\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u306e\u578b\u5f15\u6570\u306e\u63a8\u8ad6\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u307e\u3059\u3002 \u305f\u3068\u3048\u3070\u3001\u8155\u6642\u8a08\uff08wristWatch\uff09\u3084\u66f8\u7c4d\uff08Book\uff09\u306a\u3069\u3001\u53cb\u9054\u3078\u306e\u8d08\u308a\u7269\uff08Gift\uff09\u3092\u4f8b\u306b\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u3092\u7406\u89e3\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3001\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u3067\u306a\u3044\u30af\u30e9\u30b9\u306e <code>Book<\/code> \u3068 <code>WristWatch<\/code>\u3001\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u306e <code>Gift<\/code> \u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u3068\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">class Book {...}\nclass WristWatch {...}\nrecord Gift&lt;T&gt;(T t) {}<\/pre>\n<p>\u53cb\u9054\u304c\u8d08\u308a\u7269\u3092\u53d7\u3051\u53d6\u308a\u3001\u5305\u307f\u3092\u958b\u3053\u3046\u3068\u3059\u308b\u3068\u3069\u3046\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u304b\uff1f \u4ee5\u4e0b\u306b\u5b9a\u7fa9\u3055\u308c\u308b unwrap \u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u3068\u3057\u307e\u3059\u3002 \u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001<code>unwrap<\/code> \u30e1\u30bd\u30c3\u30c9\u306f <code>Gift&lt;wristwatch&gt; (var watch)<\/code> \u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002 \u3053\u306e\u30d1\u30bf\u30fc\u30f3\u306b\u306f\u3059\u3067\u306b\u30ec\u30b3\u30fc\u30c9\u540d <code>Gift<\/code> \u3067\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u578b\u306e <code>WristWatch<\/code> \u304c\u6307\u5b9a\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u3001\u30d1\u30bf\u30fc\u30f3\u5909\u6570 <code>watch<\/code> \u306f <code>WristWatch<\/code> \u578b\u3068\u3057\u3066\u63a8\u8ad6\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">void unwrap(Gift&lt;wristwatch&gt; obj) {\n   if (obj instanceof Gift&lt;wristwatch&gt; (var watch)) {\n       watch.setAlarm(LocalTime.of(10, 25));\n   }\n}<\/pre>\n<p>\u4ee5\u4e0b\u306e\u4f8b\u306f Java 19 \u3067\u306f\u52d5\u4f5c\u3057\u307e\u305b\u3093\u304c\u3001Java 20 \u3067\u306f\u52d5\u4f5c\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">void unwrapAndRevealSurprise(Gift&lt;WristWatch&gt; obj) {\n    if (obj instanceof Gift&lt;WristWatch&gt; (var watch)) {\n        System.out.println(watch);\n    }\n}\n\nvoid unwrapAndUseGift(Gift&lt;WristWatch&gt; obj) {\n    if (obj instanceof Gift(var gift)) {\n        gift.setAlarmTime(LocalTime.now());\n    }\n}\n\nvoid birthdayGift(Gift&lt;DiamondStudded&lt;WristWatch&gt;&gt; gift) {\n    if (gift instanceof Gift&lt;DiamondStudded&lt;WristWatch&gt;&gt;(DiamondStudded(var personalizedGift))) {\n        System.out.println(personalizedGift);\n    }\n}\n\nvoid performanceBonus(Gift&lt;DiamondStudded&lt;WristWatch&gt;&gt; personalizedGift) {\n    if (personalizedGift instanceof Gift(DiamondStudded(var actualGift))) {\n        System.out.println(\"Wrist watch\" + actualGift);\n    }\n}<\/pre>\n<p>\u3053\u308c\u306b\u3088\u3063\u3066\u3001\u7db2\u7f85\u7684\u306a switch \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30c8\u306e\u52d5\u4f5c\u304c\u3069\u306e\u3088\u3046\u306b\u5909\u5316\u3059\u308b\u304b\u3092\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u306b\u3088\u308b\u7db2\u7f85\u7684\u306a switch \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30c8<\/h3>\n<p>\u59cb\u3081\u308b\u524d\u306b\u3001\u57fa\u672c\u3092\u78ba\u304b\u3081\u307e\u3057\u3087\u3046\u3002 \u6b21\u306e\u753b\u50cf\u3067\u306f\u3001switch \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u307e\u305f\u306f switch \u5f0f\u3067\u30bb\u30ec\u30af\u30bf\u30fc\u5f0f\u304c\u53c2\u7167\u3057\u3066\u3044\u308b\u3082\u306e\u3092\u793a\u3057\u3066\u3044\u307e\u3059\uff08switch \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30c8\u306b\u6e21\u3059\u5909\u6570\u307e\u305f\u306f\u5f0f\uff09\u3002<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2023\/03\/3-1.png\" alt=\"\" \/><\/figure>\n<p>switch \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3068 switch \u5f0f\u306e\u69cb\u6587\u3067\u30bb\u30ec\u30af\u30bf\u30fc\u5f0f\u306e\u5024\u3092 case \u30e9\u30d9\u30eb\u306e\u578b\u30d1\u30bf\u30fc\u30f3\u307e\u305f\u306f\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u306b\u4e00\u81f4\u3055\u305b\u3088\u3046\u3068\u3059\u308b\u5834\u5408\u3001\u69cb\u6587\u3092\u7db2\u7f85\u7684\u306b\u3057\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002 \u8a00\u3044\u63db\u3048\u308b\u3068\u3001\u30bb\u30ec\u30af\u30bf\u30fc\u5f0f\u306f case \u30e9\u30d9\u30eb\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b 1 \u3064\u4ee5\u4e0a\u306e\u5024\u306b\u4e00\u81f4\u3057\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002<\/p>\n<p><code>Object<\/code> \u578b\u306e\u3088\u3046\u306b\u30b5\u30d6\u30bf\u30a4\u30d7\u306e\u6570\u304c\u5b9a\u307e\u3089\u306a\u3044\uff08\u305d\u308c\u3092\u62e1\u5f35\u3057\u3066\u3044\u308b\u4ed6\u306e\u30af\u30e9\u30b9\u306e\u6570\u304c\u78ba\u5b9a\u3057\u306a\u3044\uff09\u578b\u306e\u5834\u5408\u306f\u3001<code>default<\/code> \u306e case \u30e9\u30d9\u30eb\u3092\u5b9a\u7fa9\u3059\u308b\u304b\u3001<code>Object<\/code> \u578b\u81ea\u4f53\u3092 case \u30e9\u30d9\u30eb\u306e 1 \u3064\u3068\u3057\u3066\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u3067\u7db2\u7f85\u7684\u306a switch \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30c8\u306b\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002 \u7db2\u7f85\u7684\u306a switch \u5f0f\u3068\u7db2\u7f85\u7684\u306a switch \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u306e\u6709\u52b9\u306a\u4f8b\u3092\u4ee5\u4e0b\u306b\u793a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">String exhaustiveSwitchExpression(Object obj) {\n   return switch (obj) {\n       case String s -&gt; \"String\";\n       case Apple apple -&gt; \"Apple\";\n       default -&gt; \"everything else\";\n   };\n}\n\nvoid exhaustiveSwitchStatement(Object obj) {\n   switch (obj) {\n       case String s -&gt; System.out.println(\"String\");\n       case Apple apple -&gt; System.out.println(\"Apple\");\n       case Object object -&gt; System.out.println(\"everything else\");\n   };\n}<\/pre>\n<p>sealed \u30af\u30e9\u30b9\u306e\u3088\u3046\u306a\u30b5\u30d6\u30bf\u30a4\u30d7\u304c\u78ba\u5b9a\u3057\u3066\u3044\u308b\u4e00\u90e8\u306e\u578b\u3067\u306f\u3001<code>default<\/code> \u30e9\u30d9\u30eb\u3092\u4f7f\u3063\u3066\u7db2\u7f85\u7684\u306a switch \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u307e\u305f\u306f switch \u5f0f\u3092\u5b9a\u7fa9\u3059\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\u3002 \u4ee5\u4e0b\u306b\u4f8b\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">sealed interface HighProtein permits Egg, Cheese {}\nfinal class Egg implements HighProtein {}\nfinal class Cheese implements HighProtein {}\n \nint processHighProtein(HighProtein protein) {\n   return switch (protein) {\n       case Egg egg -&gt; 2;\n       case Cheese cheese -&gt; 10;\n   };\n}<\/pre>\n<p>\u305f\u3060\u3057\u3001<code>HighProtein<\/code> \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u901a\u5e38\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\uff08\u3064\u307e\u308a\u3001\u975e sealed \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\uff09\u3068\u3057\u3066\u5b9a\u7fa9\u3059\u308b\u5834\u5408\u306f\u524d\u306e\u30b3\u30fc\u30c9\u3067\u306f\u30b3\u30f3\u30d1\u30a4\u30eb\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u3067\u306f\u3001\u30bb\u30ec\u30af\u30bf\u30fc\u5f0f\u304c\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u3067\u3042\u308b\u5834\u5408\u306e\u7db2\u7f85\u7684\u306a case \u30e9\u30d9\u30eb\u306e\u5b9a\u7fa9\u65b9\u6cd5\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u306f\u3001\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u306b\u5bfe\u3057\u3066\u30de\u30c3\u30c1\u30f3\u30b0\u3055\u308c\u307e\u3059\u3002 \u4ee5\u4e0b\u306f\u3001\u5225\u306e <code>HimalayanApple<\/code> \u30af\u30e9\u30b9\u306b\u3088\u3063\u3066\u62e1\u5f35\u3055\u308c\u3066\u3044\u308b <code>Apple<\/code> \u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30af\u30e9\u30b9\u3001<code>Egg<\/code> \u30af\u30e9\u30b9\u3068 <code>Cheese<\/code> \u30af\u30e9\u30b9\u3067\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b <code>HighProtein<\/code> sealed \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3001\u304a\u3088\u3073\u578b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u53d7\u3051\u5165\u308c\u3066\u305d\u306e\u578b\u306e 2 \u3064\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u5b9a\u7fa9\u3059\u308b <code>Dish<\/code> \u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u306e\u4f8b\u3067\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">public class Apple {}\npublic class HimalayanApple extends Apple{}\n\nsealed public interface HighProtein permits Egg, Cheese {}\npublic final class Egg implements HighProtein {}\npublic final class Cheese implements HighProtein {}\n\npublic record Dish&lt;T&gt; (T x, T y){}<\/pre>\n<p>\u3053\u306e\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u30af\u30e9\u30b9 <code>Dish<\/code> \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u5207\u308a\u66ff\u3048\u305f\u5834\u5408\u306b\u52d5\u4f5c\u3059\u308b\u3001\u307e\u305f\u306f\u52d5\u4f5c\u3057\u306a\u3044\u8907\u6570\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f <code>orderAppleDish<\/code> \u30e1\u30bd\u30c3\u30c9\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u306f\u3001\u578b <code>Dish&lt;Apple&gt; appleDish<\/code> \u306e\u30e1\u30bd\u30c3\u30c9\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u53d7\u3051\u5165\u308c\u3001\u305d\u308c\u3092\u5207\u308a\u66ff\u3048\u306a\u304c\u3089\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u3068\u7167\u5408\u3057\u307e\u3059\u3002 \u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u306f\u52d5\u4f5c\u3059\u308b\u3068\u601d\u3044\u307e\u3059\u304b\uff1f<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">    int orderAppleDish(Dish&lt;Apple&gt; appleDish) {\n        return switch (appleDish) {\n            case Dish&lt;Apple&gt;(Apple apple, HimalayanApple himalayanApple) -&gt; 1;\n            case Dish&lt;Apple&gt;(HimalayanApple himalayanApple, Apple apple) -&gt; 2;\n        };\n    }<\/pre>\n<p><code>HimalayanApple<\/code> \u30af\u30e9\u30b9\u306f <code>Apple<\/code> \u30af\u30e9\u30b9\u3092\u62e1\u5f35\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u524d\u306e switch \u5f0f\u3092\u7db2\u7f85\u7684\u306a switch \u306b\u3059\u308b\u306b\u306f\u4ee5\u4e0b\u306e 2 \u3064\u306e\u7d44\u307f\u5408\u308f\u305b\u304c\u5fc5\u8981\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>Apple, Apple<br \/>HimalayanApple, HimalayanApple<\/p>\n<p>\u4ee5\u4e0b\u306e\u753b\u50cf\u306f IntelliJ IDEA \u304c\u524d\u306e\u30b3\u30fc\u30c9\u3092\u30a8\u30e9\u30fc\u3068\u3057\u3066\u691c\u51fa\u3057\u3001\u30b3\u30fc\u30c9\u3078\u306e\u79fb\u52d5\u3068\u4fee\u6b63\u3092\u652f\u63f4\u3059\u308b\u69d8\u5b50\u3092\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<figure class=\"wp-block-image alignnone wp-image-16062\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2023\/03\/generic-records.gif\" alt=\"\" \/><\/figure>\n<p>\u53c2\u8003\u307e\u3067\u306b\u3001\u4ee5\u4e0b\u306f\u524d\u306e\u753b\u50cf\u3067\u4fee\u6b63\u3055\u308c\u305f\u5f8c\u306e\u6700\u7d42\u7684\u306a\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">class Apple {}\nclass HimalayanApple extends Apple{}\nrecord Dish&lt;T&gt; (T ingredient1, T ingredient2) {}\n\npublic class FoodOrder {\n\n    int orderAppleDish(Dish&lt;Apple&gt; appleDish) {\n        return switch (appleDish) {\n            case Dish&lt;Apple&gt;(HimalayanApple apple1, HimalayanApple apple2) -&gt; 4;\n            case Dish&lt;Apple&gt;(Apple apple, HimalayanApple himalayanApple) -&gt; 1;\n            case Dish&lt;Apple&gt;(HimalayanApple himalayanApple, Apple apple) -&gt; 2;\n            case Dish&lt;Apple&gt;(Apple apple1, Apple apple2) -&gt; 3;\n        };\n    }\n\n}<\/pre>\n<p>\u4ee5\u4e0b\u306e sealed \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u4f7f\u7528\u3059\u308b\u4f8b\u3068\u3001\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9 <code>Dish<\/code> \u3092\u4f7f\u3063\u305f\u3053\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306e\u5b9f\u88c5\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">sealed public interface HighProtein permits Egg, Cheese {}\npublic final class Egg implements HighProtein {}\npublic final class Cheese implements HighProtein {}\n\npublic record Dish&lt;T&gt; (T x, T y){}<\/pre>\n<p>\u3042\u308b\u4eba\u304c\u98df\u3079\u7269\u3092\u6ce8\u6587\u3057\u3001<code>Dish<\/code> \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3068\u578b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306e <code>HighProtein<\/code> \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u6e21\u3057\u305f\u3068\u3057\u307e\u3059\u3002 \u3053\u306e\u5834\u5408\u3001\u4ee5\u4e0b\u306e switch \u5f0f\u306f\u7db2\u7f85\u7684\u3067\u3059\u3002<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2023\/03\/4-1.png\" alt=\"\" \/><\/figure>\n<p>\u53c2\u8003\u307e\u3067\u306b\u3001\u30b3\u30fc\u30c9\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">public class FoodOrder {\n\n    int orderHighProteinDish(Dish&lt;HighProtein&gt; proteinDish) {\n        return switch (proteinDish) {\n            case Dish&lt;HighProtein&gt;(HighProtein protein, Egg egg) -&gt; 1;\n            case Dish&lt;HighProtein&gt;(HighProtein protein, Cheese cheese) -&gt; 2;\n        };\n    }\n\n}<\/pre>\n<p><code>HighProtein<\/code> \u306f sealed \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3067\u3042\u308b\u305f\u3081\u3001\u4ee5\u4e0b\u306e switch \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30c8\u306e\u6700\u521d\u306e case \u30e9\u30d9\u30eb\u306f <code>Egg<\/code> \u3068 <code>Cheese<\/code> \u306e\u3069\u3061\u3089\u304b\u304c\u30ec\u30b3\u30fc\u30c9 Dish \u306e 2 \u3064\u76ee\u306e\u5024\u3068\u3057\u3066\u6e21\u3055\u308c\u308b\u5834\u5408\u306b\u3082\u5bfe\u5fdc\u3067\u304d\u307e\u3059\u3002 \u3064\u307e\u308a\u3001case \u30e9\u30d9\u30eb\u306f 3 \u3064\u3057\u304b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u304c\u7db2\u7f85\u7684\u306a switch \u5f0f\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">public class FoodOrder {\n\n    int orderHighProteinDish(Dish&lt;HighProtein&gt; proteinDish) {\n        return switch (proteinDish) {\n            case Dish&lt;HighProtein&gt;(Egg protein, HighProtein highProtein) -&gt; 1;\n            case Dish&lt;HighProtein&gt;(Cheese cheese, Egg egg) -&gt; 2;\n            case Dish&lt;HighProtein&gt;(Cheese cheese1, Cheese cheese2) -&gt; 4;\n        };\n    }\n\n}<\/pre>\n<p>\u7db2\u7f85\u7684\u306a switch \u3068\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u306b\u95a2\u3059\u308b\u6b21\u306e\u6700\u5f8c\u306e\u4f8b\u3067\u306f\u3001switch \u5f0f\u306e\u6700\u521d\u306b\u3042\u308b case \u30e9\u30d9\u30eb\u4e00\u5f0f\u306f\u7db2\u7f85\u7684\u3067\u3042\u308a\u307e\u305b\u3093\u3002\u6700\u521d\u306e\u6750\u6599\u304c <code>HighProtein<\/code> \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3067\u30012 \u3064\u76ee\u306e\u5024\u304c <code>Egg<\/code> \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3067\u3042\u308b\u9ad8\u305f\u3093\u3071\u304f\u6599\u7406\u3092\u51e6\u7406\u3067\u304d\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3067\u3059\u3002<\/p>\n<pre>    int orderHighProteinDish(Dish&lt;HighProtein&gt; proteinDish) {\n        return switch (proteinDish) {\n            case Dish&lt;HighProtein&gt;(Egg protein, Cheese cheese) -&gt; 1;\n            case Dish&lt;HighProtein&gt;(Cheese cheese, Egg egg) -&gt; 2;\n            case Dish&lt;HighProtein&gt;(HighProtein highProtein, Cheese cheese) -&gt; 3;\n        };\n    }\n<\/pre>\n<p>\u524d\u306e\u30b3\u30fc\u30c9\u306b case \u30e9\u30d9\u30eb\u3092\u3082\u3046 1 \u3064\u8ffd\u52a0\u3057\u3066\u3001\u7db2\u7f85\u7684\u306a switch \u5f0f\u306b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">            case Dish&lt;HighProtein&gt;(HighProtein highProtein, Egg egg) -&gt; 10;<\/pre>\n<h3>\u62e1\u5f35 for \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3067\u306e\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u306e\u4f7f\u7528<\/h3>\n<p>Java 20 \u3067\u306f\u3001\u62e1\u5f35 <code>for<\/code> \u30eb\u30fc\u30d7\u306e\u30d8\u30c3\u30c0\u30fc\u3067\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u3092\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002 \u305f\u3060\u3057\u3001\u8907\u6570\u306e case \u30e9\u30d9\u30eb\u3092\u5272\u308a\u5f53\u3066\u3089\u308c\u308b switch \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u307e\u305f\u306f\u5f0f\u306e\u5834\u5408\u3001\u62e1\u5f35 for \u30eb\u30fc\u30d7\u30d8\u30c3\u30c0\u30fc\u3067\u4f7f\u7528\u3059\u308b\u5358\u4e00\u306e\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u306f for \u30eb\u30fc\u30d7\u3067\u53cd\u5fa9\u3059\u308b\u3059\u3079\u3066\u306e\u5024\u306b\u4e00\u81f4\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 \u4e00\u81f4\u3057\u306a\u3044\u5834\u5408\u3001\u30b3\u30fc\u30c9\u306f\u30e9\u30f3\u30bf\u30a4\u30e0\u4f8b\u5916\u3092\u30b9\u30ed\u30fc\u3057\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306f\u3001<code>Point<\/code> \u30ec\u30b3\u30fc\u30c9\u3068 <code>Triangle<\/code> \u30ec\u30b3\u30fc\u30c9\u3001\u304a\u3088\u3073\u30d8\u30c3\u30c0\u30fc\u306b\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u3092\u4f7f\u7528\u3057\u3066 <code>Triangle<\/code> \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u30ea\u30b9\u30c8\u3092\u53cd\u5fa9\u3059\u308b\u62e1\u5f35 for \u30eb\u30fc\u30d7\u306e\u4f8b\u3067\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">record Point (int x, int y) { }\nrecord Triangle(Point pointA, Point pointB, Point PointC) { }\n\nlong addLowerRightCoordinates(List&lt;Triangle&gt; triangles) {\n    long sum = 0;\n    for (Triangle(Point a, Point b, Point (int x, int y)) : triangles) {\n        sum += x + y;\n    }\n    return sum;\n}<\/pre>\n<p>\u4ee5\u4e0b\u306b\u3001\u9593\u9055\u3044\u306e\u4f8b\u3092\u3044\u304f\u3064\u304b\u793a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">public class Test {\n\n    sealed interface UpperWithPermit permits PermittedRecord {}\n    record PermittedRecord(int x) implements UpperWithPermit {}\n    interface Upper {}\n    record Record(List&lt;String&gt; x) implements Upper {}\n\n    void test1(List&lt;Upper&gt; lists) {\n        for (Record(List&lt;String&gt; x) : lists) {} \n    }\n\n    void test2(List&lt;? super UpperWithPermit&gt; lists) {\n        for (PermittedRecord(var x) : lists) {} \n    }\n\n    void test3(List&lt;? super PermittedRecord&gt; lists) {\n        for (PermittedRecord(var x) : lists) {} \n    }\n\n    void test4(List lists) {\n        for (PermittedRecord(var x) : lists) {} \n    }\n\n    void test5(List&lt;?&gt; lists) {\n        for (PermittedRecord(var x) : lists) {} \n    }\n}<\/pre>\n<h2>switch \u306e\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u30f3\u30b0<\/h2>\n<p>Java 20 \u3067\u306f\u3001switch \u306e\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u30f3\u30b0\u306f 4 \u56de\u76ee\u306e\u30d7\u30ec\u30d3\u30e5\u30fc\u3068\u306a\u308a\u307e\u3057\u305f\u3002 \u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u30f3\u30b0\u3092\u307e\u3063\u305f\u304f\u77e5\u3089\u306a\u3044\u65b9\u306f\u3001\u307e\u305a\u306f<a href=\"https:\/\/blog.jetbrains.com\/idea\/2021\/09\/java-17-and-intellij-idea\/#Patternmatchingforinstanceof\">\u3053\u3061\u3089\u306e\u30ea\u30f3\u30af<\/a>\u3067 instanceof \u306b\u3088\u308b\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u30f3\u30b0\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u3092\u304a\u52e7\u3081\u3057\u307e\u3059\u3002 switch \u3067\u306e\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u30f3\u30b0\u304c\u521d\u3081\u3066\u306e\u65b9\u306f\u3001<a href=\"https:\/\/blog.jetbrains.com\/idea\/2021\/09\/java-17-and-intellij-idea\/#WelcometoPatternmatchingforswitch\">\u3053\u3061\u3089\u306e\u30ea\u30f3\u30af<\/a>\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>Java 20 \u3067\u306f\u3001\u3053\u306e\u6a5f\u80fd\u306b\u3044\u304f\u3064\u304b\u306e\u5909\u66f4\u304c\u8ffd\u52a0\u3055\u308c\u3066\u3044\u307e\u3059\u3002 switch \u306e\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u30f3\u30b0\u3092\u5217\u6319\u578b\u30af\u30e9\u30b9\u3067\u4f7f\u7528\u3057\u305f\u5834\u5408\u3001\u7db2\u7f85\u7684\u306a switch \u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u307e\u305f\u306f switch \u5f0f\u3092\u5b9f\u884c\u6642\u306b\u4e00\u81f4\u3059\u308b\u30e9\u30d9\u30eb\u3092\u691c\u51fa\u3067\u304d\u306a\u3044\u5834\u5408\u306b <code>ImcompatibleClassChangeError<\/code> \u3067\u306f\u306a\u304f <code>MatchException<\/code> \u304c\u30b9\u30ed\u30fc\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002 Java 20 \u306e\u3053\u306e\u6a5f\u80fd\u306b\u306f\u3001case \u30e9\u30d9\u30eb\u306b\u304a\u3051\u308b\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u306e\u578b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306e\u63a8\u8ad6\u306b\u95a2\u9023\u3059\u308b\u5225\u306e\u5909\u66f4\u304c\u3042\u308a\u307e\u3059\u3002 \u3053\u306e\u6a5f\u80fd\u306b\u3064\u3044\u3066\u306f\u3001\u3053\u306e\u30d6\u30ed\u30b0\u8a18\u4e8b\u306e\u300c<a href=\"https:\/\/blog.jetbrains.com\/idea\/2023\/03\/java-20-andintellij-idea\/#Exhaustiveswitchconstructswithgenericrecords\">\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u306b\u3088\u308b\u7db2\u7f85\u7684\u306a switch \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30c8<\/a>\u300d\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u8aac\u660e\u6e08\u307f\u3067\u3059\u3002<\/p>\n<h2>\u6982\u8981<\/h2>\n<p>IntelliJ IDEA\u306f\u3001\u958b\u767a\u8005\u304c\u6700\u65b0\u306e Java \u6a5f\u80fd\u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u8a8d\u77e5\u8ca0\u8377\u306e\u8efd\u6e1b\u306b\u53d6\u308a\u7d44\u3093\u3067\u3044\u307e\u3059\u3002 IntelliJ IDEA 2023.1 \u306f\u3001\u300cswitch \u306e\u30d1\u30bf\u30fc\u30f3\u30de\u30c3\u30c1\u30f3\u30b0\u300d\u3084\u300c\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u300d\u306a\u3069\u306e\u8a00\u8a9e\u6a5f\u80fd\u306b\u5bfe\u3059\u308b Java 20 \u306e\u5909\u66f4\u70b9\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u307e\u3059\u3002 \u3053\u308c\u3089\u306e\u6a5f\u80fd\u3067\u6700\u3082\u91cd\u8981\u306a\u5909\u66f4\u306f\u3001\u62e1\u5f35 for \u30d8\u30c3\u30c0\u30fc\u3067\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u3092\u4f7f\u7528\u3067\u304d\u308b\u6a5f\u80fd\u3068\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30ec\u30b3\u30fc\u30c9\u30d1\u30bf\u30fc\u30f3\u306e\u578b\u5f15\u6570\u306e\u578b\u63a8\u8ad6\u3078\u306e\u6539\u5584\u3067\u3059\u3002<\/p>\n<p>Happy Coding!<\/p>\n<p><strong>\u30aa\u30ea\u30b8\u30ca\u30eb\uff08\u82f1\u8a9e\uff09\u30d6\u30ed\u30b0\u6295\u7a3f\u306e\u4f5c\u8005\uff1a<\/strong><\/p>\n\n    <div class=\"about-author \">\n        <div class=\"about-author__box\">\n            <div class=\"row\">\n                <div class=\"about-author__box-img\">\n                    <img decoding=\"async\" src=\"https:\/\/secure.gravatar.com\/avatar\/?s=200&#038;r=g\" width=\"200\" height=\"200\" alt=\"\" loading=\"lazy\"  class=\"avatar avatar-200 wp-user-avatar wp-user-avatar-200 photo avatar-default\">\n                <\/div>\n                <div class=\"about-author__box-text\">\n                                                        <\/div>\n            <\/div>\n        <\/div>\n    <\/div>\n","protected":false},"author":1394,"featured_media":336490,"comment_status":"closed","ping_status":"closed","template":"","categories":[5088],"tags":[8095,6744,8097,8099,155,76,477],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/idea\/342563"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/idea"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/types\/idea"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/users\/1394"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/comments?post=342563"}],"version-history":[{"count":10,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/idea\/342563\/revisions"}],"predecessor-version":[{"id":342576,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/idea\/342563\/revisions\/342576"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/media\/336490"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/media?parent=342563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/categories?post=342563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/tags?post=342563"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/cross-post-tag?post=342563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}