简体   繁体   中英

Unreachable statement in Switch statement

I have this code, and first "break;" is red underlined with error "Unreachable statement". I guess it is about figure brackets that method should return int, but I have to use if and switch statements, please, I appreciate any help

  public Fragment getItem(int position) {
            if (getIntent().getExtras() != null) {
                char intentA = getIntent().getCharExtra("A", 'A');

                switch (intentA) {
                    case 'A':
                        mPager.setCurrentItem(0);
                        return LetterFragment.newInstance(intentA);
                    **break;**
                    case 'B':
                        mPager.setCurrentItem(1);
                        return LetterFragment.newInstance(intentA);
                    break;
                    case 'C':
                        mPager.setCurrentItem(3);
                        return LetterFragment.newInstance(intentA);
                    break;
                }
            }
            return new LetterFragment();

        } 

You don't need break statement in switch case after the return statement. Remove all break statements.

The break statements will never be run (they are unreachable), because you always return before the break statement. Remove the break statements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM