Skip to content

constructor-impl of Kotlin value class is not called #32324

@k163377

Description

@k163377

The init block of the value class can contain processing.

@JvmInline
value class Value(val value: Int) {
    init {
        if (100 < value) throw IllegalArgumentException()
    }
}

This will be compiled into a method named constructor-impl in the bytecode.

When instantiating a value class using Java reflection, both constructor-impl and box-impl must be called in order to be equivalent to instantiating it on Kotlin.
On the other hand, there is no evidence that constructor-impl is called in the spring-framework, and only box-impl seems to be called.

Is this an intentional design?

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)theme: kotlinAn issue related to Kotlin supporttype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions