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:
data class FileEntryWithTags(
@Embedded val fileEntry: FileEntry,
@Relation(
parentColumn = FileEntry.COLUMN_UUID,
entityColumn = Tag.COLUMN_ID,
associateBy = @Junction(FileEntryTagCrossRef::class)
)
val tags: List<Tag>
)
In Java, an annotation type is a form of an interface, so you can implement it and use an instance. As an alternative to this mechanism, Kotlin lets you call a constructor of an annotation class in arbitrary code and similarly use the resulting instance.
By prefixing the annotation with @get: the resulting bytecode will have the annotation on the generated getter function: // Decompiled from the resulting Kotlin Bytecode @SomeAnnotation @Nullable public final String getSomeProperty() { return this. someProperty; }
annotated methods will get called for each HTTP request if you don’t specify the value element of this annotation. The value element can be a single or multiple form names or request parameters that the init binder method is applied to. This annotation is used on fields. The annotation is a meta annotation that indicates a web mapping annotation.
If you need to specify a class as an argument of an annotation, use a Kotlin class ( KClass ). The Kotlin compiler will automatically convert it to a Java class, so that the Java code can access the annotations and arguments normally. Copied!
An annotation can't be used as the annotations argument. I wonder: how come (what I think is) the same concept working in Java but not in Kotlin? Also, is there a way to go around this?
Kotlin doesn't let you do that. You get the error 'Kotlin: An annotation can't be used as the annotations argument' Well hell, we have annotations which require you do exactly that. Here is the fragment giving us problems
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>
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With