https://openjdk.org/jeps/456arrow-up-right
This demo showcases unnamed variables and unnamed patterns (_) in modern Java, using several small examples:
_
Throwaway locals: assigns to _ when a value is computed only for side effects, and demonstrates that _ can be reused.
Unnamed exception parameter: a catch block that intentionally ignores the exception object.
catch
Ignoring extracted data: processes a queue of triples and discards the third element using _.
Unnamed lambda parameters: in a Map.forEach and in a callback, ignores parameters that aren’t needed.
Map.forEach
Unnamed record pattern components: pattern-matches a Point and ignores one component, including a switch example.
Point
switch
Last updated 21 days ago