Android Typedef Annotations edit

IntDef Annotations

This annotation ensures that only the valid integer constants that you expect are used.

The following example illustrates the steps to create an annotation:


public abstract class Car {

    //Define the list of accepted constants

    //Tell the compiler not to store annotation data in the .class file
    //Declare the CarType annotation
    public @interface CarType {}

    //Declare the constants
    public static final int MICROCAR = 0;
    public static final int CONVERTIBLE = 1;
    public static final int SUPERCAR = 2;
    public static final int MINIVAN = 3;
    public static final int SUV = 4;

    private int mType;

    public int getCarType(){
        return mType;

    public void setCarType(@CarType int type){
        mType = type;

They also enable code completion to automatically offer the allowed constants.

When you build this code, a warning is generated if the type parameter does not reference one of the defined constants.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents
64 Menu
112 Loader
115 Typedef Annotations
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close