5 ms·
JEP draft: Type operator expressions in the JVM
- kodablah 8y ago> The syntax will allow any single type descriptor to be modified by an optional suffix, which has the effect of constraining the original type descriptor in an ad hoc, programmable manner So, if I had a JVM dependent type lib, could my type be "Ljava/math/BigInteger;/$contract[$nonNegative;]"? Are we sure we want this buried in the name? EDIT: There's a similar example "I/$interval[$ge;0;]" which seems to imply some might want to burying a mini expression language in there. I can think of a lot of uses and a lot of abuses. But at the very least, it allows you to give arguments to types that persist in the bytecode.
- BonesJustice 8y agoPresumably such things would be expressed in the source and documentation, and flagged by the IDE. The proposed enhancement to type descriptors provides a way of retaining that information so it can be leveraged by the VM. Alternatively, it could be extracted by the IDE, compiler, or other tooling when only the compiled class files are available.
- kjeetgill 8y agoJDK11 introduces CONSTANT_dynamic[0] so anything expressed by that type descriptor string should also be expressible as a call to a bootstrap method at link time. I think. Never played with it myself but here is a "bestiary"[1] of possibilities that CONSTANT_dynamic already opens up. [0]: http://openjdk.java.net/jeps/309 http://openjdk.java.net/jeps/309 [1]: https://github.com/forax/exotic https://github.com/forax/exotic
- kodablah 8y agoSure, or really just bury the method call/descriptor as an arg. It's not that much different than annotations.
- jontro 8y agoI think this helps being able to solve these kind of hacks: https://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/TypeLiteral.html https://google.github.io/guice/api-docs/latest/javadoc/index...
- kodablah 8y agoSure, among other things, it lets you reify generics by adding them as args in the type descriptor.