Java / Lombok Interview questions
What is @Builder.Default used for?
Normally, a field's default field initializer (like private int retries = 3;) is silently
ignored when using @Builder, because the builder constructs the object through its own
constructor logic rather than the field's normal initialization path — without
@Builder.Default, an unset field in the builder would end up as its type's zero value
(0, null, etc.), not the initializer you wrote.
@Builder public class RetryConfig { @Builder.Default private int maxRetries = 3; // without this annotation, unset -> 0, not 3 } RetryConfig cfg = RetryConfig.builder().build(); // cfg.getMaxRetries() == 3, thanks to @Builder.Default
This is a common gotcha for developers new to Lombok's builder: field initializers you'd expect to "just
work" are silently dropped unless explicitly marked with @Builder.Default, so any field with a
meaningful default value needs this annotation to actually preserve that default when built via the builder.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
