Will JEP 169: Value Objects and JEP 218: Generics over Primitive Types specifications work together?
Or better, is the following scenario possible?
@jvm.internal.value.ValueCapableClass
final class Tuple<T1, T2> {
private final T1 t1;
private final T2 t2;
// ...
}
and then
// t1 and t2 flattened because they are ints
final Tuple<int, int> tuple;
I'm asking this because I haven't seen an example of a @ValueCapableClass
using generic types, only examples like this one:
@jvm.internal.value.ValueCapableClass
final class MyValue {
final int x, y;
// ...
}
I read from JEP 218: Generics over Primitive Types (emphasis mine):
Generic type arguments are constrained to extend Object, meaning that they are not compatible with primitive instantiations unless boxing is used, undermining performance. With the possible addition of value types to Java (subject of a separate JEP), this restriction becomes even more burdensome. We propose to remedy this by supporting specialization of generic classes and interfaces when instantiated with primitive type arguments. We propose to remedy this by supporting specialization of generic classes and interfaces when instantiated with primitive type arguments.
and
With the eight primitive types being the only ones hostile to generics, this is tolerable but annoying; with the advent of value types, this restriction would be far more painful.
but it's unclear to me whether they are meant to work together (218
is an extension of 169
), or generic @ValueCapableClasses
can be used only for non-generic classes.
According to this Brian Goetz's talk
So it seems
generics
are in the process of being supported in future builds.