I have a Kotlin data class with 15 fields. When I construct an instance of this class in my Kotlin code using the primary constructor, I can make use of useful features such as:
- omitting fields with default values
- use named parameters
However, when constructing an instance of this Kotlin class from Java code, I am faced with the fact I need to provide all 15 parameters in the constructor, in the correct order, without the ability to name them. This is especially inconvenient when this Java code is a unit test, where I'm not really interested in filling all those fields, but only one or two useful for the test.
When using purely Java, I would not face this problem, as I would use a (Lombok) builder to construct the instance of the object, having the flexibility to only provide the fields I'm interested in.
Is there a way to mitigate this problem, or is this the price I have to pay for mixing Java and Kotlin?