Marcin Orlowski Marcin Orlowski - 1 year ago 61
Android Question

@IntDef annotation and return value from other's code that cannot be annotated or how to temporarily disable annotation from affecting the code?

I am using IntDef from Android Support annotation in my code (but my question is wider in scope so please keep reading :) like this:

public class UiLockMode
public @interface AllowedValues {}

public static final int DEFAULT = 0;
public static final int NONE = 1;
public static final int VISIBLE = 2;
public static final int TRANSPARENT = 3;

Next, I got some other methods annotated with it like this:

protected void setLockMode(@UiLockMode.AllowedValues int lockMode) {

At that point is all fine and nice but the problem shows up whenever I'd like to pass return value from other methods to
, like i.e. from Parcelable implementation:

private Foo(Parcel in) {

In such case my IDE complains that I am only allowed to use
. But
is not my method so I cannot annotate its return value and make all this happy. I am also almost sure this is not unique use case but I failed to find the way to either temporarily disable
annotation from complaining here or to "cast" return value from
to make
not complaining.

So my questions are: is there any way of solving this problem? Maybe I am missing something obvious about annotations but maybe I shall be creating bug report to make Google address this problem instead?

Any input or thought appreciated.

Answer Source

You can suppress IntDef Lint warnings for a method by annotating it with the following:


You can also disable these warnings for individual statements and whole classes - see the Android Tools site for further documentation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download