SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 30 day free trial to unlock unlimited reading.
43.
301:EnhancedEnums
Enumの拡張。二年前から取組中。
Before
public enum JDKNumber {
YEAR(18),
FULL(18.3);
public final Number version;
JDKNumber(Number version) {
this.version = version;
}
}
float jdkVersion = (float)JDKNumber.Full.version;
43
44.
After
public enum JDKNumber<T extends Number> {
YEAR<Integer>(18),
Full<Float>(18.3);
public final T version;
JDKNumber(T version) {
this.version = version;
}
}
float jdkVersion = JDKNumber.Full.version;
44
45.
305:Patternmatchingforinstanceof
Before
if (obj instanceof Double) {
Double d = (Double) obj;
// d を使った処理
}
After
if (obj instanceof Double d) {
// d を使った処理
}
switch でも同じように書ける
switch (obj) {
case Integer i:
// intの時にやらせたい処理
case Double d:
// doubleの時にやらせたい処理
} 45
46.
355:TextBlocks
Before
String html = "<html>n" +
" <body>n" +
" <p>Hello, world</p>n" +
" </body>n" +
"</html>n";
After
String html = """
<html>
<body>
<p>Hello, world</p>
</body>
</html>
""";
46