3 ms·
No, there is no tuple support yet in Java. That would require something like variadic generics or a special compile time syntax sugar for tuples as the sole use
by BlackFly 5y ago
No, there is no tuple support yet in Java. That would require something like variadic generics or a special compile time syntax sugar for tuples as the sole use of variadic generics.
With the pattern matching the best you are going to get is nasty boiler plate like
var returnedTuple = getMeTwoThings();
if (returnedTuple instanceof MyTupleType(Foo foo, Bar bar)) {
// Do something with foo and bar
} else {
// Not reachable unless refactoring, etc. So panic here.
}
That else clause is so terrible you'd probably just rather use the getters from the type.
- evacchi 5y agoI think there is ongoing discussion to support var MyTupleType(Foo foo, Bar bar) = getMeTwoThings(); which IIRC may be even simplified to var MyTupleType(foo, bar) = getMeTwoThings(); EDIT: found it https://mail.openjdk.java.net/pipermail/amber-spec-experts/2021-March/002916.html https://mail.openjdk.java.net/pipermail/amber-spec-experts/2... let Point(var x, var y) = aPoint