Android Studio Introduces Anonymous Inner Class

I created a completely new Android application in Android Studio 0.3.6 with the LoginActivity.java function created for me. When I look at the onCreate function, I see the following code:

enter image description here

But when I click on the highlighted code (view)-> { , Android Studio displays what I expected to see:

 findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { attemptLogin(); } }); 

My questions

  • What is called?
  • Why does Android Studio do this?
  • Is this something I can use as it prints much less?
+6
source share
1 answer

It does code folding similar to Java 8 lambda expressions (see docs ), even if your code is not actually compiled with Java 8; it's just a convenience for a more compact display.

If you want to use them yourself, you can use Android Studio with Java 1.7 as the compilation language, but you will need to use the build tools v19 or later, and if you use certain language features, this will only work on phones with Kit Kat or later . However, lambda functions will not cause problems.

+2
source

Source: https://habr.com/ru/post/958729/


All Articles