0

When I write a lambda expression in Android studio, it sometimes turns itself into a normal anonymous class, and I can't bring it back. How can I prevent the IDE from doing this? And what is the cause?

If I click on the green highlighted area:

enter image description here

It turns into this:

enter image description here

And there is no way to bring it back. CTRL+Z does not help. I also noticed that this happens on certain actions done within the lambda expression. For example, I just deleted some code inside of it and this happened. This happens all the time.

I read that lambda expressions are not yet supported, and I guess that the IDE is just "simulating" a lambda expression. But I still want to prevent it from changing my code.

piotrek1543
  • 19,130
  • 7
  • 81
  • 94
Kidades
  • 600
  • 2
  • 9
  • 26
  • 7
    IDE isn't really changing your code, it just shows you anonymous classes as lambda expressions to make the code look more compact. If you open this java file in text editor, you'll see an anonymous class there, not lambda. – egor.zhdan Jan 09 '16 at 14:53
  • 1
    Just stumbled upon the same feature in AS, turns out (at least today) that on left side of code view there is + (or -) button that opens / closes that code block. – ahaaman Jul 26 '18 at 09:31

1 Answers1

1

Android SDK does not yet support Java 8. You should not use any Java 8 feature.

Aitor Viana
  • 933
  • 6
  • 15