Search code examples
kotlinannotations

kotlin, what is @param used for before the annotation type


In java class with annotation:

public final class Info {

    private Info() {

    }

    public static class InfoAction {

        public static final String OPEN = "open";
        public static final String VIEW_ALL = "view_all";

        @Retention(RetentionPolicy.SOURCE)
        @StringDef({OPEN, VIEW_ALL})
        public @interface Action {
        }

        public String mAction;

        public InfoAction(@Action String action) {
            this.mAction = action;
        }
    }

IDE convert to kotlin:

class Info private constructor() {
    class InfoAction(@param:Action var infoAction: String) {
        @kotlin.annotation.Retention(AnnotationRetention.SOURCE)
        @StringDef(OPEN, VIEW_ALL)
        annotation class Action

        companion object {
            const val OPEN = "open"
            const val VIEW_ALL = "view_all"
        }
    }
}

it has @param:Action, but replace with @Action it works as well.

what is this @param here for, and can the @Action be used?


Solution

  • @param is for constructor parameter

    detail:

    https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets