This might be a bug; however I am unsure. In java switch statements thats are non-exhaustive, should produce a warning of sorts in the IDE. In this case, Android Studio 3.0 (B6)
Given the enum class Foo
public enum Foo {
FOO_ONE,
FOO_TWO
}
and then later used in a switch statement as this:
switch(fooEnum){
case FOO_ONE:
//Do something here
break;
}
Shouldn't the compiler warn me in some way, that this switch statement doesn't use all the Foo enum options?
The compiler should not give a warning, this is an action for a linter. You can enable this exact feature in Android Studio. If you click the button in the very bottom right of the Android Studio window that looks like a little dude's head, there is a "Configure Inspections" button.
Then under "Java-> Control Flow Issues -> Enum 'switch' statement that misses case" enable that option.
No they shouldn't. Non-exhaustive switch statements aren't illegal. Producing a warning would be a compiler specific option at most (and truthfully I think a really really annoying one). There's nothing in the language which requires a compiler to warn you of anything. Although there likely is a lint setting that would turn that on, it seems the type of thing lint would do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With