1

In the following example, FolderItem::class belongs to the value property of Junction, even though it is not explicitly stated:

class FolderWithItems(
        @Embedded
        val folder: Folder,
        @Relation(
                associateBy = Junction(
                        FolderItem::class,
                        parentColumn = "folder_id",
                        entityColumn = "item_id"
                ),
                parentColumn = "id",
                entityColumn = "id"
        )
        val items: List<Item>
)

It compiles and runs the same as if I were to write out:

value = FolderItem::class

What is the Kotlin principle/rule/language feature that allows you to not have to specify value = in this case?

1 Answers1

0

Just like in Java, a special case is the value parameter; its value can be specified without an explicit name

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
  • Ok, that makes sense. I think what confused me is that `Junction` has '@interface' in its class header which I was previously not familiar with, but [this answer](https://stackoverflow.com/a/918417/11566289) helped me understand what that means. Also, what's interesting is that if I remove for example `parentColumn = `, then Android Studio says "only named arguments are available for Java annotations", yet it doesn't complain when `value =` is removed. –  Jul 13 '19 at 07:04
  • @glucaio Actually, if Junction is an annotation here (which makes sense and I overlooked), then my answer was incorrect. I've fixed it. – Alexey Romanov Jul 13 '19 at 07:09
  • Ok, thanks for fixing. I had no idea. It all makes sense now. –  Jul 13 '19 at 07:17