Skip to content

Remove unnecessary casts to long #3400

Description

@shollander

Expected behavior

When use a defaultValue with a long value, ex:

class MyObject {
    private Long myField;
    ....
}

class MyMapper {
    @Mapping(target="myField", source="myField", defaultValue="0L")
    abstract MyObject map(MyOtherObject obj);
}

The generated code should not produce any compiler warnings.

Actual behavior

class MyMapperImpl {
    abstract MyObject map(MyOtherObject obj) {
        ...
        if(obj.getMyField() != null) {
            myObject.setMyField( obj.getMyField() );
        } else {
            obj.setMyField( (long) 0L );         //   <--- This cast is unnecessary and produces a warning when compiling with -Xlint:all
        }
    }
}

Steps to reproduce the problem

See expected behavior above.

MapStruct Version

1.5.5

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions