June 6, 2016

Lambda Expression in Java 8

Introduction

Lambda expression is used to replace one method classes/interface with inline code.

Syntax

(arg1, arg2...) -> { body }

  • Declaring the types of the parameters is optional.
  • Using parentheses around the parameter is optional if you have only one parameter.
  • Using curly braces is optional (unless you need multiple statements).
  • The “return” keyword is optional if you have a single expression that returns a value.

Examples

Reference

http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html

No comments: