Major OpenJDK projects
Local variable type inference ("var")
*For declaring local variables only, can use car instead of type
*Isn't one of Java's strengths that types are declared explicitly?
Example of local variable type inference ("var"): cluttered code
Example of local variable type inference ("var"): clean code
*A "two-dimensional" string literal
*"Smart" policy for removal of incidental whitespace
*New String APIs
Example of text block with syntactic noise
Example of text block without syntactic noise
*Concerning the new line conventions between Linux and Windows,
if you take this code from Linux to Windows.
The new line separator is simply the "NL" Character not the blind feed character as opposed to carriage return linefeed.
*Concerning the leading whitespace,
the string before the leftmost line is called the incidental white space, and it is stripped away.
*Historically, switch is a statement
*In these cases, intent can be expressed better with an expression
Example of switch statement
Example of switch expression
*Exhaustive -- no default clause needed, as all cases covered
*Exhaustiveness allows compiler to distinguish between "I want to handle all cases explicitly" from "I want to handle some cases but not others".
*A transparent, shallowly immutable data aggregate class
*A record is a class
*Records are restricted class
*Cannot be subclassed
*Are shallowly immutable
Example before use of Record
Example with use of Record
*The constructor, equals(), hashCode(), toString(), and component accessors --x() & y()-- are all provided automatically.
record use case
*A local record, like a local class. A class has too much syntactic overhead to use this way.
*Allows a class to control its subclasses
Example of sealed types
Example of a variant of sealed types
*"permits" clause inferred
Pattern matching for instanceof - before it
*type name repeated, obscur syntax. Most of the time there is a cast after instanceof
Pattern matching for instanceof
*Provide a binding variable name with instanceof
Pattern matching for instanceof - now
*there is a new local variable initialized by cast, whom scope is subsequent block
Pattern matching for instanceof - a more complicated example: old equals
Pattern matching for instanceof - a more complicated example: new equals
Putting it all together
*Just a bunch of individual features, right?
*Features designed to work together
*Future enhancements in-progress:
=>add type patterns to switch expressions
Putting it all together - Remember the previous sealed types
Putting it all together - Application to switch: type pattern
*no default case, since Shape is a sealed type with exactly two subtypes
Putting it all together - Application to switch: deconstruction pattern
Putting it all together - Application to instanceof: deconstruction pattern
*1 is the value of the radius
Links of project Amber
We just sent you an email. Please click the link in the email to confirm your subscription!