pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/mtumilowicz/java11-lambda-type-inference

"stylesheet" href="https://github.githubassets.com/assets/primer-0b53c3bf3393e2ed.css" /> GitHub - mtumilowicz/java11-lambda-type-inference: Exploring basic features of lambda type inference in Java 11.
Skip to content

mtumilowicz/java11-lambda-type-inference

Repository files navigation

Build Status

java11-lambda-type-inference

The main goal of this project is to show how to use type inference for lambda expressions.

Reference: https://medium.com/the-java-report/java-11-sneak-peek-local-variable-type-inference-var-extended-to-lambda-expression-parameters-e31e3338f1fe
Reference: https://stackoverflow.com/questions/50225672/java-11-local-variable-syntax-for-lambda-parameters-applications

preface

We have three ways to provide types to lambdas:

  • explicit
    Predicate<String> isLowercase = (String str) -> str.equals(str.toLowerCase());
    
  • implicit
    Predicate<String> isLowercase = str -> str.equals(str.toLowerCase());
    
  • inference
    Predicate<String> isLowercase = (var str) -> str.equals(str.toLowerCase());
    

As you may see - java has two mechanisms for type inference on local lambda expression variables (as mentioned above - implicit and inference).

Previously (prior to 11), if we wanted to use modifiers on lambda formals we had to use explicit syntax, now it is possible to write:

Predicate<String> isLowercase = (@NonNull var str) -> str.equals(str.toLowerCase());

which is a very concise, coherent and elegant way.

project description

In LambdaLocalTypeInferenceTest we provide full examples of the mentioned functionality.

About

Exploring basic features of lambda type inference in Java 11.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy