An annotation can't be used as the annotations argument

Viewed 6134

I get a error, although do exactly the same that documentation says. Documentation:

data class PlaylistWithSongs(
    @Embedded val playlist: Playlist,
    @Relation(
         parentColumn = "playlistId",
         entityColumn = "songId",
         associateBy = @Junction(PlaylistSongCrossRef::class)
    )
    val songs: List<Song>
)

My problem:

Error

data class FileEntryWithTags(
        @Embedded val fileEntry: FileEntry,
        @Relation(
                parentColumn = FileEntry.COLUMN_UUID,
                entityColumn = Tag.COLUMN_ID,
                associateBy = @Junction(FileEntryTagCrossRef::class)
        )
        val tags: List<Tag>
)
1 Answers

Looks like the Android documentation has a mistake in it. The Annotations - Kotlin Programming Language page from the Kotlin reference tells us:

If an annotation is used as a parameter of another annotation, its name is not prefixed with the @ character:

annotation class ReplaceWith(val expression: String)

annotation class Deprecated(
        val message: String,
        val replaceWith: ReplaceWith = ReplaceWith(""))

@Deprecated("This function is deprecated, use === instead", ReplaceWith("this === other"))

So your code should be:

data class FileEntryWithTags(
        @Embedded val fileEntry: FileEntry,
        @Relation(
                parentColumn = FileEntry.COLUMN_UUID,
                entityColumn = Tag.COLUMN_ID,
                associateBy =  Junction(FileEntryTagCrossRef::class)
        )
        val tags: List<Tag>
)
Related