Theo Pearson-Bray
Theo Pearson-Bray

Reputation: 775

Android Studio StyleRes annotation gives warning on Kotlin var

I have a publicly visible Int to hold the current application theme.

var themeId: Int = R.style.AppTheme
    private set

If I annotate the value with @StyleRes

@StyleRes var themeId: Int = R.style.AppTheme
    private set

I get a warning

This annotation does not apply for type void; expected int or long

If I change the variable to val, the error is not displayed. I can also get rid of the error by adding the @JvmField annotation, but this removes the ability to have the private setter.

Am I using the annotation incorrectly, or is this a problem with Kotlin on Android Studio?

Edit:

The getter can be annotated

var themeId: Int = R.style.AppTheme
    private set
    @StyleRes get

Upvotes: 6

Views: 1445

Answers (1)

tango24
tango24

Reputation: 474

This is a known issue, see KT-16506.

Upvotes: 6

Related Questions