Inspectopedia
 
2024.3

Enhanced 'for' with a record pattern can be used

Warning
New
Last modified: 03 December 2024

Reports local variable declarations and accessors to record components that can be replaced with pattern variables in enhanced `for` statements, which are usually more compact.

Example:

Can be replaced with:

  • Use the Nesting depth limit option to specify the maximum number of nested deconstruction patterns to report

  • Use the Maximum number of record components to deconstruct option to specify the maximum number of components, which a record can contain to be used in deconstruction patterns

  • Use the Maximum number of not-used record components option to specify the maximum number of components, which are not used in for statement

This inspection depends on the Java feature 'Record patterns in for-each loops', which is available since Java X.

New in 2023.1