[JAVA] Verification by Resource annotations

By adding resource annotation to Android argument, it can be verified whether it exists in the resource.

before


    private void handleColorChange(int stringResId, int colorResId) {
        int prefColor = pref.getInt(getString(stringResId), 0);

        ...
    }

after


    private void handleColorChange(@StringRes int stringResId, @ColorRes int colorResId) {
        int prefColor = pref.getInt(getString(stringResId), 0);

        ...
    }

Android Studio will tell you as follows.

Wrong スクリーンショット 2017-03-14 21.03.28.png

Positive スクリーンショット 2017-03-14 21.03.49.png

reference

Improve Code Inspection with Annotations | Android Studio

Recommended Posts

Verification by Resource annotations
Rails singular resource routing by resource