Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 673
Theo Pearson-Bray Avatar asked Jul 06 '17 15:07

Theo Pearson-Bray


1 Answers

This is a known issue, see KT-16506.

like image 155
tango24 Avatar answered Oct 04 '22 02:10

tango24