r/java • u/vladmihalceacom • Dec 11 '25
Modern Bytecode Instrumentation with ByteBuddy – Rafael Winterhalter | The Marco Show
https://www.youtube.com/watch?v=AzfhxgkBL9s
40
Upvotes
r/java • u/vladmihalceacom • Dec 11 '25
View all comments
Show parent comment
2
u/JustJustust Dec 12 '25
Your example is approximately what I had in mind, yes. To go with the scenario,
Postobjects would be loaded from the db or send from the frontend, so there's really no default forPost.titlethat I would want in production code.But then for tests of course I need some content, so I tend to factory methods that come prefilled with sensible test values and the option to customize using the builder pattern.
For example this could be a test I'd write for some fictional use case
The infrastructure that allows this uses a
PostBuilderunder the hood.If we had Kotlins
copymethod I wouldn't need this, I would writecreatePost().copy { visible = false }, but I think that's analogous to withers not to default or named params.And usages like that are most of the builder use I see.
Edit: To respond specifically to "why do you see a difference between production and test code": I see a difference in how objects are usually instantiated is all.