Java / MapStruct Java Interview questions part 2
What is the difference between @Mapper(uses =...) and a default method?
Both let MapStruct delegate a conversion it can't infer on its own, but they differ in scope and reuse.
| uses = {...} | default method |
| Points to an external mapper/helper class. | Lives inside the current mapper interface. |
| Logic can be shared across multiple mappers. | Scoped to the single mapper that declares it. |
| Good for reusable, general-purpose conversions. | Good for one-off logic specific to this mapping. |
A common pattern is to start with a default method for a quick conversion and later promote it to a shared helper class referenced via uses once more than one mapper needs the same logic.
More Related questions...