In the onCreate method, I have the code for the Activity :

 val map = mapOf(1 to "one", 2 to "two", 3 to "three") Log.e(TAG, "$map") 

and separately in the same Activity I have an infix method to :

 infix fun Any.to(other: Any) : Pair<Any, Any> { Log.e(TAG, "internal to $other") return Pair(this, other) } 

if everything is so, then everything works logically, in the logs you can see that this method is called 3 times:

internal to one

internal to two

internal to three

{1 = one, 2 = two, 3 = three}

and if only $other removed from the logged line:

 infix fun Any.to(other: Any) : Pair<Any, Any> { Log.e(TAG, "internal to") return Pair(this, other) } 

for some reason, this method is called 2 times ... At least in Logcat in this case the output is:

internal to

internal to

{1 = one, 2 = two, 3 = three}

Why it happens? It seems like I only change the line with logging ...

PS I tried to turn on debugging, put a breakpoint on the line with logging - and in this case the to method is executed three times, and the output in Logcat is the same as in the first example (with $other ) ...

UPD

And the same strange behavior manifests itself when executing the following code:

 Log.d(TAG, "${ listOf(1, 2, 3, 4, 8, 9) .map { Log.d(TAG, "map") it * it } .find { it > 6 } }") 

When you run this code snippet, Logcat displays:

map

map

9

despite the fact that the code

 Log.d(TAG, "${ listOf(1, 2, 3, 4, 8, 9) .map { Log.d(TAG, "map $it") it * it } .find { it > 6 } }") 

displays

map 1

map 2

map 3

map 4

map 8

map 9

9

  • Kotlin version? I checked on JVM version 1.2.71 - everything works as it should. - Eugene Krivenja
  • Is the same. Version of Android Studio - 3.2. - Ksenia
  • Although now tried in AS 3.0.2 - the same situation. And, by the way, I tried to display more on the UI, and not in Logcat - everything is fine there. Ie, it seems, the problem is in Logcat ... - Ksenia

0