I would like to use a switch statement as in Java 1.7 which also allows switch(someString)
. However if I change the java compiler to 1.7 the project breaks and I either have to go back to 1.5 or use android tools-> fix project
.
Is there any way to use switch with Strings in android development?
EDIT
Personally, I have not tried, but according to the Android System Requirements page, it is unsupported. That said, it does not mean that it wouldn't work, just that you are unlikely to receive much/any help on the subject from Google/Android.
JDK 5 or JDK 6 (JRE alone is not sufficient)
On a potentially positive note, (found with the help of @Emil H and his comment) I have found these bit of information online:
From Dalvik on Wikipedia:
Programs are commonly written in a dialect of Java and compiled to bytecode. Then they are converted from Java Virtual Machine-compatible .class files to Dalvik-compatible .dex (Dalvik Executable) files...
If the bytecode doesn't change from version 6 to 7 (excluding the added invokedynamic
mentioned by @David Schwartz, which switch
statements should not be using.), then it should work...
You should be able to use JDK7 with android. Check this answer to a related question:
https://stackoverflow.com/a/7481063/355499
EDIT:
Tried it out locally and everything works fine with JDK7 (it's what I use when developing). However, I can't find a way to change the compliance level from 1.6 to 1.7 in my android project. If you really want to do this I guess you would have to resort to building your project by some other means than using Eclipse. For instance using an ant script or similar. Might be a bit more work than it is worth though.
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