3

Is there any issues with using Java 1.8 for an android project targetting API 14 and above? I can't find any documentation on this and would like to use Optionals.

Edit: Mainly focused on optionals (not duplicate).

StackOverflowed
  • 5,854
  • 9
  • 55
  • 119

3 Answers3

1

for Optionals only you can also use guava - if you want other features you might want to have a look at retro-lambda

Also think twice about Optional - try to do it at compile-time as much as possible with Annotations like @Nullable @NonNull - same effect - more speed

ligi
  • 39,001
  • 44
  • 144
  • 244
0

As far as I know you can't do this. Android works with a subset of the Java APIs and with the Java language as-of Java 1.5 (from memory). So Optional won't be available in the APIs included in Android and 1.8 language features (lambdas, etc) are not available to you when targetting Android as a platform.

You might be able to compile to Java 1.5 (language level) using the 1.8 compiler; but then you may as well just use Java 1.5. (Keeping in mind that you still need to run you project through all the Android SDK steps need to deploy it on Dalvik: you can't just build a .jar as you would a regular Java app.)

This has been my experience - though I am not a full-time Android developer.

Paul
  • 3,009
  • 16
  • 33
0

Not as far as I know.

You can use retrolambda project to use lambda expressions, but I don't know any project that back ported Optional's

Robert Estivill
  • 12,369
  • 8
  • 43
  • 64