data class Hoge( val id:Int, val name:String) { class HogeBuilder() { var id:Int? = null var name:String? = null fun build() : Hoge = Hoge( id = requireNotNull(id), name = requireNotNull(name) ) } } fun main(args: Array<String>) { var builder = Hoge.HogeBuilder() builder.id = 1 builder.name = "hoge" var e:Hoge = builder.build() println(e.id) println(e.name) }