3

I am trying to replace some of the enumerations in my source with IntDef annotation. I have been following this documentation.

I have a variable for holding a ViewMode which was previously an enumeration. Now I have changed it to some thing like below.

@Retention(RetentionPolicy.SOURCE)
@IntDef({ViewMode.VIEW_MODE_LIST_VIEW, ViewMode.VIEW_MODE_CARD_VIEW})
public @interface ViewMode {
    int VIEW_MODE_LIST_VIEW = 0;
    int VIEW_MODE_CARD_VIEW = 1;
}

@ViewMode
public int currentViewMode = ViewMode.VIEW_MODE_LIST_VIEW;

Now to test whether this is safe or not I have done the following in a method

this.currentViewMode = 987; //currentViewMode should be 0 or 1. Nothing else.

But this is now not giving me a compilation error. Am I missing something here?

Ajeesh A
  • 143
  • 1
  • 10

1 Answers1

1

You will not get a compilation error, because the enumerated annotations are just lint checks: see Improve Your Code with Lint

You should see the error-marker directly in Android Studio or when you run android lint checks from the command line: see Improve Your Code with Lint

Note: you can also configure your build to automatically run the lint checks:
see SO: Run lint when building android studio projects
But running the linter takes some time, so you may choose to run it only for your release builds or only on your CI server.

TmTron
  • 17,012
  • 10
  • 94
  • 142