Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "(v) ->" mean in Android Studio?

When in Android Studio I will often see my anonymous inner class for a View.onClickListener compressed to a (v)-> until I click on it, much the same way my code will display as if strings are hard-coded when my code uses a string resource id. Google searches for '"(v) ->" android' are not giving me anything. Is this some more advanced compact coding notation that I can use?

enter image description here

like image 814
Thomas Hodges Avatar asked Mar 17 '23 21:03

Thomas Hodges


2 Answers

It is called lambda expressions, which is a feature of Java 8 and is not yet supported in Android. In your case, it is just the onClick's View parameter. It is the android studio to compact anonymous inner classes.

like image 69
Blackbelt Avatar answered Mar 19 '23 11:03

Blackbelt


Android does not support lambdas. Android Studio does this so the code looks like the latest Java.

like image 40
Alexander Kulyakhtin Avatar answered Mar 19 '23 09:03

Alexander Kulyakhtin