2

I'm trying to define an IntDef interface in Kotlin but then use those constants in Java. I am able to access it, but I get an IDE Lint error when I try to do a equals operator on it. Though, a different comparison operator (<, >) works fine. Even using 'Objects.equal()' works, just not ==. Anyone have any idea about this?

Error: Must be one of: 1L, 2L

My Kotlin Class

class RandomClass{
    ...
    @IntDef(STATE_1, STATE_2)
    @Retention(AnnotationRetention.SOURCE)
    annotation class MyState

    companion object {
        const val STATE_1 = 1L
        const val STATE_2 = 2L
    }

Accessing the Annotation in Java where Error Occurs

void myFunction(@RandomClass.MyState long state){
    if(state == RandomClass.STATE_1){
        ...
    }
}

My Temp Fix for this

void myFunction(@RandomClass.MyState long state){
    if(Objects.equal(state, RandomClass.STATE_1)){
        ...
    }
}
Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
phazedlite
  • 161
  • 2
  • 10
  • What exactly is the error that you get? – hotkey Oct 16 '17 at 22:17
  • No, on Java side it is only an IDE warning. On Kotlin, it is currently not supported. You have to always check for it. – Joshua Oct 17 '17 at 02:36
  • Possible duplicate of [How to use Android Support typedef annotations in kotlin?](https://stackoverflow.com/questions/35976002/how-to-use-android-support-typedef-annotations-in-kotlin) – Cristan Oct 30 '17 at 10:54
  • @Cristan It isn't. This has to do with the equals operator in java when referring to an intdef defined in kotlin (which is possible). – phazedlite Oct 31 '17 at 05:06

0 Answers0