Does Kotlin memoize repeated constructor calls?

Suppose I have some code like this:

val x = 5 items.forEach { SomeObject(x).someMethod() } 

Does Kotlin construct a new SomeObject on every pass of forEach ?

EDIT: really I’m not asking about memoization, but about whether the compiler can optimize the object construction away altogether. I understand that mutable data dependencies would often make that impossible. But are there any circumstances where it can be done?

submitted by /u/sacheie
[link] [comments]