Skip to content

Use switch Expressions for JDK13 and newer #4062

Description

@hduelme

Use case

Switch Expressions added in JDK13 give a better way of writing switches.
Currently value mappings uses normal switches only.

Generated Code

Instead of generating:

        switch ( b ) {
            case "A": a = ValueMapper.A.A;
            break;
            case "B": a = ValueMapper.A.B;
            break;
            default: throw new IllegalArgumentException( "Unexpected enum constant: " + b );
        }

the generated output could be

        ValueMapper.A a = switch (b) {
            case "A" -> A.A;
            case "B" -> A.B;
            default -> throw new IllegalArgumentException("Unexpected enum constant: " + b);
        };

For enums constants the default branch is not needed.

Possible workarounds

No response

MapStruct Version

1.6.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions