What does the language level in Android studio 0.3.2 do?

In the latest version of Android Studio (0.4.2), a new parameter was added when creating a new project, namely Language Level I want to know what this means and the consequences of choosing any of the options provided. The document does not give me a clear idea about this, and I do not want to choose the option when I do not know what this will lead to? Thanks

+3
android android-studio
source share
3 answers

This is about what level of Java language you want to use. KitKat supports full support for Java 7, Gingerbread, and support for Java 6, and earlier versions are Java 5. At least when it comes to the core Java APIs. Approximately the same setting is mentioned here .

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

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

actually compiles into the same thing as

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

done.

The β€œtry with a resource” construct, on the other hand, cannot be compiled into legitimate Java-compatible code and therefore is exclusive to applications that require KitKat and up.

+3
source share

The answer can be formulated better, IMHO. docs is clear about Java 7 and below.

  • This setting affects Java features that you can use in your source code .
  • All Java language features you use will be compiled in such a way that the code works in all versions of Android, except for the "try with resources" language function.
  • From the docs: β€œIf you want to use try with resources, you will also need to use minSdkVersion 19. You also need to make sure that Gradle uses version 1.7 or later of the JDK. (And version 0.6.1 or later of the Android Gradle plugin. ) "
+1
source share

Support for Java 7 was added to build tools 19. You can now use features such as the diamond operator, multi-user capture, try-with-resources, strings in radio buttons, etc. Add the following to your build.gradle.

 android { compileSdkVersion 19 buildToolsVersion "19.0.0" defaultConfig { minSdkVersion 7 targetSdkVersion 19 } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } } 

Gradle 1.7+, Android gradle 0.6 plugin required. +.

Please note that only using resources requires minSdkVersion 19. Other functions work on previous platforms.

0
source share

All Articles