Andriy Antonov
Andriy Antonov

Reputation: 1510

bug in kotlin annotation?

here are two code examples

java:

public class Q {

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({LOL.one, LOL.two})
    @interface Lol{}

    public final class LOL{
        public final static int one = 1;
        public final static int two = 2;
    }

    public Q(){
        q(1);
    }

    void q (@Lol int q){

    }
}

kotlin:

class Q {

    @Retention(AnnotationRetention.SOURCE)
    @IntDef(LOL.one, LOL.two)
    internal annotation class Lol

    object LOL {
        const val one = 1L
        const val two = 2L
    }

    init {
        q(1)
    }

    internal fun q(@Lol q: Int) {

    }
}

probleb here: in java calling this q(1); will show you an error like :"must be one of..."

but in kotlin there are no any error message, so we can put as parameter any long we want... so we lose advantages of annotation as parameter...

looks like a bug or I am dooing something wrong?

Upvotes: 1

Views: 417

Answers (1)

Joshua
Joshua

Reputation: 6241

This is not a bug. This is a feature that is not yet implement in Kotlin. It is planned in the future.

Upvotes: 2

Related Questions