Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the language level setting in android studio 0.3.2 Do?

In the latest release of Android Studio (0.4.2), a new setting has been added when creating a new project, namely Language Level I want to know what that refers to, and the consequence of selecting any of the provided options. The doc doesn't give me a clear picture of this and i don't want to select an option when i don't know what that will result in? Thanks

like image 223
SamAko Avatar asked Mar 21 '26 17:03

SamAko


2 Answers

It's about what Java language level you want to use. KitKat supports full Java 7, Gingerbread and up support Java 6 and older versions are Java 5. At least when it comes to the core Java APIs. Roughly the same setting is mentioned here.

You can often use language features that were added in one version in an older version if the compiler knows how to do it. For example the Diamond Operator was added in Java 7 but you can still use that feature in Java 6 since

List<String> list = new ArrayList<>();

actually compiles into the same thing as

List<String> list = new ArrayList<String>();

did.

The "try with resource" construct on the other hand can't be compiled into legal Java 6 compatible code and is therefore exclusive to Apps that require KitKat and up.

like image 60
zapl Avatar answered Mar 25 '26 00:03

zapl


The answer can be phrased better, IMHO. The docs are clear about Java 7 and below.

  1. This setting affects which Java language features you can use in your source code.
  2. All Java language features that you use will be compiled so that the code will work in all Android versions, except for the "try with resources" language feature.
  3. From the docs: "If you want to use try with resources, you will need to also use a minSdkVersion of 19. You also need to make sure that Gradle is using version 1.7 or later of the JDK. (And version 0.6.1 or later of the Android Gradle plugin.)"
like image 37
Nick Westgate Avatar answered Mar 25 '26 01:03

Nick Westgate



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!