r/androiddev • • Mar 03 '20

Java 14 Arrives with a Host of New Features

https://blogs.oracle.com/javamagazine/java-14-arrives-with-a-host-of-new-features
12 Upvotes

18 comments sorted by

14

u/ballzak69 Mar 03 '20

Remind me in 10 years when it's usable on Android.

12

u/JakeWharton Head of sales at Bob's Discount ActionBars Mar 04 '20

You've had good NPEs for 5(ish?) years since we've had ART.

Aside from records, all of the other language features should be able to be made available once we can actually build with Java 14. This isn't as far off as it seems. Building with JDK 11 is seemingly coming soon with IntelliJ 2020.1 only supporting JBR 11 (JetBrains Runtime 11, their OpenJDK fork) forcing Android Studio's hand. After that it shouldn't take much to actually enable Java 11 language features. Once you get past Java 9, the difference between running on Java 11 or Java 14 should be minimal such that it can be supported with minimal effort. I will be pushing hard for this.

Records probably require changes to ART and the framework. They're only in preview in 14 and actually more a Java 15/16 feature, but they currently have a base class, reflection APIs, and rely on new bootstrap methods for invoke dynamic. D8/R8 will desugar the invoke dynamic stuff away just like it does for lambdas, and in theory it could do the same for the base type provided it actually ships in an Android version once stable in the JDK. You're unlikely to see the reflection APIs though. That means changes to the Dalvik bytecode format which means you do need to wait N years before your APK can start actually shipping with that Dalvik version.

All is to say, it's not as hopeless at it seems. Despite the overwhelmingly mediocre showing publicly, things are moving forward to a world where this isn't unrealistic in a much quicker timeframe.

7

u/eygraber Mar 04 '20

I look forward to the near future, where due to your heroic efforts, I can read the comments on posts like this without seeing the obligatory "It'll be nice to use this in X years" comment.

1

u/pjmlp Mar 04 '20

I wish there would be a must have Kotlin library with hard dependency on modern Java APIs and JVM features, that still wouldn't work with your fixes in Android, and rewriting it to Android would handicap its feature list.

Maybe that way Android management would finally change their attitude.

It is such a made up example that it will never happen though, so thanks for the improvements done thus far.

3

u/ballzak69 Mar 04 '20

I appreciate the de-sugar effort, but when some parts are/becomes available but not other, i feel it's a bit of a gamble to even be writing code, or using third-party libraries, for a newer Java, e.g. Java8 functional interface and streams are still missing.

I just expected the Android team would have come up with a more permanent solution by this time, e.g. letting the APK include an JRE, or it being specified in the manifest then downloaded from the Play Store.

4

u/JakeWharton Head of sales at Bob's Discount ActionBars Mar 04 '20

Functional interfaces and streams shipped 4 years ago and are reaching common minSdks now. They're also desugared to API 14 by AGP 4.0 and newer. There's no limitation to using them.

6

u/remindditbot Mar 03 '20 edited Mar 08 '20

ballzak69, your reminder arrives in 10 years on 2030-03-03 19:42:51Z. Next time, remember to use my default callsign kminder.

r/androiddev: Java_14_arrives_with_a_host_of_new_features

2 OTHERS CLICKED THIS LINK to also be reminded. Thread has 3 reminders.

OP can Delete Comment · Delete Reminder · Get Details · Update Time · Update Message · Add Timezone · Add Email

Protip! We have a subreddit at r/reminddit!


Reminddit · Create Reminder · Your Reminders · Questions

1

u/gryffindor14 Mar 04 '20

1

u/ballzak69 Mar 04 '20

I have. It's nice, but very limited.

0

u/butterblaster Mar 03 '20 edited Mar 03 '20

Why are they introducing an alternative to colons for switch statements? Seems like they’re just adding noise.

Edit: I mean, why introduce the arrow syntax for both switch statements and expressions? Isn’t one syntax (colons) good enough?

3

u/dpash Mar 03 '20 edited Mar 03 '20

Because otherwise you have to remember that two syntaxes can be used with expressions, but one of them doesn't work with statements. It reduces the mental load of the language. If you don't like it, don't use it. You can continue using colon syntax.

1

u/butterblaster Mar 03 '20

Sorry, I mis-stated. Why did they introduce a second syntax at all? Couldn’t a switch expression use just colons? From what I’m seeing, it’s increasing mental load from what we had before.

1

u/dpash Mar 03 '20

For multiple reasons. In particular, the new syntax does not have fall-through. They also have block scopes. These are not true of the old syntax.

1

u/butterblaster Mar 04 '20

Ah, so using arrows changes the behavior. Makes sense, then.

2

u/dpash Mar 04 '20

Yes, they made a mistake in too readily copying the C/C++ switch statement back in 1995 thinking that it would be easier for C++ developers to move over, but it is full of places where you can shoot yourself in the foot. The new syntax is designed to make it harder to accidentally introduce bugs, like forgetting to include a break statement.

1

u/pjmlp Mar 04 '20

It wasn't a mistake per se, rather trying to cater to the C and C++ folks regarding language adoption.

Just like C's copy-paste compatibility is seen as mistake in modern C++, due to the security exploits it opens up, however it was a huge factor regarding C++'s adoption in the mid-90's.