Revisit BeanUtils.instantiateClass to work consistently with Kotlin and Java classes #22531
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
BeanUtils.instantiateClass
is an interesting way to create a class as it takes care of kotlin features behind the scenes for you. There is a slightly mismatch with Java though.If a parameter is not available for a primitive type, we need to specify the default value for the primitive type (i.e.
0
forint
andfalse
forboolean
). With Kotlin, you have to passnull
as the parameter may have a default value that we shouldn't be overriding.Consider the following example:
Let's assume we have a value for the
value
parameter and no information for thecounter
orflag
.Java requires us to provide
[0, false, "my value"]
Kotlin requires us to provide
[null, ,null, "my value"]
An improvement would be to provide only the latter and let the internal implementation translates
null
to the proper default value if the parameter is primitive.This will benefit spring-projects/spring-boot#8762 where we're currently computing the array differently depending on the fact the target type is kotlin or not.
The text was updated successfully, but these errors were encountered: