私はこの質問に答えようとしています。
書く代わりに:
case class Person(name: String, age: Int) {
def this() = this("",1)
}
マクロ注釈を使用して展開すると思いました:
@Annotation
case class Person(name: String, age: Int)
DefDef
そこで、次のように、マクロ注釈の impl で準引用符を使用して、新しいコンストラクターを単純な古いものとして追加しようとしました。
val newCtor = q"""def this() = this("", 1)"""
val newBody = body :+ newCtor
q"$mods class $name[..$tparams](..$first)(...$rest) extends ..$parents { $self => ..$newBody }"
しかし、それはエラーを返します:called constructor's definition must precede calling constructor's definition
それを修正する方法はありますか?私は何を取りこぼしたか?
ご覧いただきありがとうございます - ジュリアン