Why can't I put {anonymous class on a new line in Kotlin?

This question may be silly, but ... why? Personally, I like the Microsoft style, where {is in the same column as the mapping}. In all the languages ​​I used, it doesn't matter where {was posted.

But in Kotlin only this works.

image_view.viewTreeObserver.addOnGlobalLayoutListener{ }; 

And that causes an error.

 image_view.viewTreeObserver.addOnGlobalLayoutListener { }; 
+5
source share
1 answer

https://kotlinlang.org/docs/reference/grammar.html#semicolons

Since your second example has the same meaning as

 image_view.viewTreeObserver.addOnGlobalLayoutListener; { }; 

access to properties followed by an empty lambda.

+9
source

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


All Articles