Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build an Interactive Story App (Retired) Intents and Multiple Activities Adding a Second Activity

what is this setOnClickListener( (v) -> {...} )

what is this setOnClickListener( (v) -> {...} ) ?

that's not how we ended the last tutorial!

also, where is onClick() ?

2 Answers

Jacob Bergdahl
Jacob Bergdahl
29,119 Points

The onClick-listener is shortended to that syntax automatically. It's only for aesthetic reasons. Try it out for yourself in Android Studio!

It was not shortened to this automatically.........

In any case an explanation would have been helpful, I too went to the next video and noticed the code was different.

That -> notations is called a lambda expression (https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html)

It is a newer addition to java, and it replaces the old school way we did it in the previous tutorial (with the @override and whatnot). My project did not automatically change the way we did it in the tutorial, so I just edited it manually.