Posts

Showing posts with the label java 13

Java String stripIndent() method

Java String stripIndent() method String stripIndent() method added jdk 13. This method is associated with text blocks, a preview feature of the Java language. Programs can only use this method when preview features are enabled. Preview features may be removed in a future release, or upgraded to permanent features of the Java language. Returns a string whose value is this string, with incidental white space removed from the beginning and end of every line. Incidental white space is often present in a text block to align the content with the opening delimiter. For example, in the following code, dots represent incidental white space:  String html = """  ..............<html>  ..............    <body>  ..............        <p>Hello, world</p>  ..............    </body>  ..............</html>  .............."""; This method treats the incidental white space as ind...

Java - APIs for Creating Unmodifiable Collections

Several new APIs have been added that facilitate the creation of unmodifiable collections. The List.copyOf Set.copyOf Map.copyOf  methods create new collection instances from existing instances. New methods have been added to the Collectors class in the Stream package. toUnmodifiableList toUnmodifiableSet toUnmodifiableMap   These allow the elements of a Stream to be collected into an unmodifiable collection.

Lambda expressions - implicitly typed parameters

For formal parameters of implicitly typed lambda expressions, allow the reserved type name `var` to be used, so that:     (var x, var y) -> x.process(y) is equivalent to:     (x, y) -> x.process(y) An implicitly typed lambda expression must use `var` for all its formal parameters or for none of them. In addition, `var` is permitted only for the formal parameters of implicitly typed lambda expressions --- explicitly typed lambda expressions continue to specify manifest types for _all_ their formal parameters, so it is not permitted for some formal parameters to have manifest types while others use `var`. The following examples are illegal:     (var x, y) -> x.process(y)         // Cannot mix 'var' and 'no var' in implicitly typed lambda expression     (var x, int y) -> x.process(y)     // Cannot mix 'var' and manifest types in explicitly typed lambda expression In theory, it would be...