Lambda Expressions in Android Studio

I’m often asked by students from my Android courses as to how I’m able to use Lambda expressions like the following in my Android programs.

Lambda Code Folded

The short answer is: I’m not able to use them. 🙂 What I typed was the following.

Lambda Expanded

The Lambda expressions appear in the editor due to a feature of Android Studio called “Code Folding”.

Android Studio does this sort’a thing in a number of scenarios. You can tell the Lambda expression is a result of code-folding by the highlight that appears over the folded portion of code.

You can also easily identify that the Lambda expression is a result of code folding because the editor will display a plus-sign to the left of the statement. You can view the full, original statement by clicking on the plus sign.

Lamba expression substitution is controlled by the following value in the Android Studio Settings dialog.

Code Folding Settings

As this is my first post of 2014, let me take this opportunity to wish everyone … Happy New Year!!

Advertisements

2 thoughts on “Lambda Expressions in Android Studio

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s