diff --git a/builder.kt b/builder.kt new file mode 100644 index 0000000..8f487ff --- /dev/null +++ b/builder.kt @@ -0,0 +1,22 @@ +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) { + var builder = Hoge.HogeBuilder() + builder.id = 1 + builder.name = "hoge" + var e:Hoge = builder.build() + + println(e.id) + println(e.name) +}