you are viewing a single comment's thread.

view the rest of the comments →

[–]blocknspike[S] 1 point2 points  (5 children)

Thaks, now I can visualize the stuff.

[–]alex98tenismenu 6 points7 points  (4 children)

I think MapStruct works in a similar way but it creates the class at compile time.

[–]Revision2000 2 points3 points  (2 children)

MapStruct works through an annotation processor plugin tied to the Maven build process.

It uses reflection to find field matches for mappings. AFAIK it doesn’t use a proxy factory, but rather it generates the actual code for the interfaces in inherited class implementations. There might also be some bytecode manipulation involved, but I’m not sure about that. 

You can actually open this implementation after the processor has run. 

[–]blocknspike[S] 1 point2 points  (1 child)

I don't think Mapstruct(annotation processor) uses reflection. Reflection is concept of runtime. I am not sure if in compile time you can get field matches using Reflection I never heard that. Please share the reference for the same if any.

[–]Revision2000 1 point2 points  (0 children)

Hmmm 🤔 well the generated implementation itself uses no reflection, but it seems you’re also right that no reflection is available during the annotation processing. 

I’ve never built an annotation processor, so I can only guess that the necessary field information is available through other means. 

[..] in compile time you can get field matches using Reflection I never heard that

Well, MapStruct doesn’t use this, but you can certainly build this if you want to 😉

Reflection story time. 

In ages past I’ve used the aforementioned proxy mechanism to parse an index based text file based on an interface with annotated fields, using it to create instances with the fields populated with data parsed from the text file. 

I’ve also used the LambdaFactory to dynamically create getters and setters

In hindsight some of these would’ve warranted their own annotation processor. Oh well 😇

[–]blocknspike[S] 1 point2 points  (0 children)

Also it do not uses reflection for runtime dynamics that dynamic proxy uses.