Skip to content

Primary constructor parameters that are not properties does not give an error with explicit constructor #575

@TorRanfelt

Description

@TorRanfelt

Why do I get the error "This class is not serializable automatically because it has primary constructor parameters of which are not properties" in example A when B doesn't?

A:

@Serializable
class Foo(bar: Int) {
    val baz: Int

    init {
        baz = bar
    }
}

B:

@Serializable
class Foo {
    val baz: Int

    constructor(bar: Int) {
        baz = bar
    }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions