Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 364
lannyf Avatar asked Nov 15 '25 03:11

lannyf


1 Answers

@param is for constructor parameter

detail:

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

like image 165
Kent Avatar answered Nov 17 '25 21:11

Kent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!