Java language architect Brian Goetz on OpenJDK 9 and possible changes in Java Generics

SD Times just ran a great article by Alex Handy that provides a summary of a recent post to Brian Goetz’s blog.  Brian’s post goes deeper into his current thinking, and provides code examples.

He [Goetz writes] that OpenJDK 9 is looking at making generic classes easier to turn into specialized classes. The idea is that these generics that can be extended over primitives, and eventually, over value types. 

The changes being batted around now are variations of what other languages do with generic specialization. But the first proposal is to use *T at the end of a typename or bytecode to signify that the type is derived from the erasure of T, and thus needs to adjusted during specialization.

Goetz also addressed sub-types and how developers could still write fully generic code with generic methods:

“Specializing generic methods is harder than specializing classes, because VM implementations are often organized around the assumption that the set of methods in a class is fixed. There are several approaches we might take for implementing and invoking specialized generic methods. One approach would be to sidestep the problem using invokedynamic; another would be via a ‘method missing’ approach.””

© Azul Systems, Inc. 2020 All rights reserved.