Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Remove unnecessary casts to long #3400

Copy link
Copy link

Description

@shollander
Issue body actions

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.