For Java, JEP 8357464, "Enhanced Local Variable Declarations", is an extension of JEP 441, "Pattern Matching for switch". It provides local declarations and value extraction in strongly-typed code.
JEP 441 allows coders to create local references of types based on pattern-matching to avoid death by a thousand casts. If you had code like:
if(o instanceof MyType) {
MyType mt=(MyType)o;
mt.doSomething();
}
... you could replace it with something simpler:
if(o instanceof MyType mt) {
mt.doSomething();
}
This applies to switch and a few other cases as well, and the cast's loss is mourned by few, as the assignment is not only localized but very clear.
In the new JEP, the example gains some interesting twists, based on the description: you could have a pattern that matches against construction:
if(o instanceof PredicateDTO(id, RDF(predicate, subject, value)) {
log.info("Found predicate reference: {}", predicate);
// do something with subject and value, presumably
}
This extends to object construction as well, creating local attribute references instead of a central controlling object:
void PredicateOperation(PredicateDTO p) {
Predicate(subject, predicate, value) = p.rdf; // PredicateDTO is a record, presumably
logger.info("Found subject reference: {}", subject);
// do something else...
}
Other languages have deconstruction, in various flavors, and pattern matching can be quite useful, used well; Java's reputation as a verbose language has been well-deserved but slowly ebbing. This is only a preview, meant to be tried and tested by programmers to find the edge cases and problems with its implementation, and needs to be enabled explicitly in recent JVMs to work at all; have you tried it? Do you think it would make a difference in how you code, or how well you code Java?