Android Studio Beta (0.8) has a nifty new feature where it checks that some int
parameters are not arbitrary integers, but rather have some properties.
(Thanks to @CommonsWare for the heads up).
There are Java annotations to support these checks in your own code. They can all be found in the android.support.annotations
package:
IdRes
DrawableRes
LayoutRes
StringRes
In this case, for example, I could use:
private void mySetContentView(@LayoutRes int resourceId) {
setContentView(resourceId);
}
and Android Studio will check that the provided resource id is indeed for a layout.
Moreover, these annotations are exported, so they can be especially useful when designing a library.
Sources: