Background
I wrote a wrapper around a default Snackbar.make
method to apply custom styling to my Snackbar
instances. The method signature of my custom wrapper is as follows:
public static Snackbar makeCustom(
@NonNull View view,
@StringRes int resId,
@Snackbar.Duration int duration)
where the Snackbar.Duration
annotation is defined in android.support.design.widget.Snackbar.java
as follows:
/**
* @hide
*/
@IntDef({LENGTH_INDEFINITE, LENGTH_SHORT, LENGTH_LONG})
@IntRange(from = 1)
@Retention(RetentionPolicy.SOURCE)
public @interface Duration {}
When I invoke makeCustom
with the following arguments:
makeCustom(
activity.findViewById(android.R.id.content),
messageResId,
Snackbar.LENGTH_SHORT);
I see the following error in my IDE (Android Studio):
I see no such error if I directly invoke Snackbar.make
, which has the following signature:
public static Snackbar make(
@NonNull View view,
@StringRes int resId,
@Duration int duration) {
It would appear that when used in my own method signature, Android Studio fails to recognize that values satisfying either of the following constraints
@IntDef({LENGTH_INDEFINITE, LENGTH_SHORT, LENGTH_LONG})
@IntRange(from = 1)
should be considered valid, instead expecting that values satisfy both of the above constraints simultaneously (which is impossible, since LENGTH_INDEFINITE
, LENGTH_SHORT
and LENGTH_LONG
have values -2
, -1
and 0
respectively).
Questions
- Am I applying the
Snackbar.Duration
annotation properly? - If so:
- Is the flagged error an Android Studio bug?
- Is this weird behavior perhaps why the annotation is marked as hidden in the source code?