Yes it is safe to use them.
switch
on String
was introduced into Java by changing the compiler to implement the necessary conversion into byte-code using no new instructions. That is, the change is a compiler one only.
Providing the implementation is similar in Android, there is no technical restriction preventing an APK compiled under SDK 19, which supports switch
on String
being used on a device running prior to version 19.
Indeed, I'm fairly sure I used this property myself. All you need to do is make sure that the targetSDKversion
and maxSDKversion
are >= 19
. The minSDKversion
can be lower, because of the property I discussed above.
The Java implementation of this was under Project Coin and is covered in detail at the Oracle website. https://blogs.oracle.com/darcy/entry/project_coin_string_switch_anatomy
See also this answer: Android coding with switch (String)
See also the developer docs for Gradle plugin