6
votes

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
1
have you tried @field:StyleRes or @get:StyleRes?holi-java
Both give the same message as before.Theo Pearson-Bray
how about private @StyleRes var themeId: Int = R.style.AppTheme?holi-java
The same message still occurs. I did just realise that I can annotate the getter, as added to the question.Theo Pearson-Bray
so , it can working as you expected. it doesn't matter. since kotlin has a lot of features has not ready done.holi-java

1 Answers

5
votes

This is a known issue, see KT-16506.