安卓Kotlin面试题 41-50

时间:2024-03-12 13:48:54

//add private constructor if necessary

class Car( val model: String?,val year: Int) {

        private constructor(builder: Builder) : this(builder.model, builder.year)

        class Builder {
                var model: String? = null
                private set

                var year: Int = 0
                private set

                fun model(model: String) = apply {

                        this.model = model

                 }

                fun year(year: Int) = apply {

                        th