ex data class in kotlin -
import com.github.pozo.KotlinBuilder
@KotlinBuilder
data class ContactInfo(val phoneNumbers: List<PhoneNumber> = emptyList(),
val emails: List<EmailAddress> = emptyList(),
val addresses: List<PostalAddress> = emptyList()
)
The create function within the generated builder looks like:
public ContactInfo create() { return new ContactInfo(phoneNumbers, emails, addresses); }
The create here uses an all args constructor. However, if the object builders never set a value for one mandatory field (addresses field, for example) the create() call using an all args constructor will try to set addresses to null, which will throw an NPE type error since this value can't be null in the target kotlin object.
I would like a way for the create() method to:
- leverage the default values in Kotlin that an object may have (usually non-nullable types have this), setting a field to the default value if a default exists
This would be amazing and very helpful to generate more accurate builders!!
ex data class in kotlin -
The create function within the generated builder looks like:
public ContactInfo create() { return new ContactInfo(phoneNumbers, emails, addresses); }The create here uses an all args constructor. However, if the object builders never set a value for one mandatory field (addresses field, for example) the create() call using an all args constructor will try to set addresses to
null, which will throw an NPE type error since this value can't be null in the target kotlin object.I would like a way for the create() method to:
This would be amazing and very helpful to generate more accurate builders!!