Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,118 Points

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

Eric Beasley
Eric Beasley
7,822 Points

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.