1
我想創建一個生成輔助構造函數{的主體)的宏。是否有可能做到這一點,而不訴諸宏觀註釋? (即宏觀天堂插件)是否有可能在Scala中創建沒有宏註釋的輔助構造函數?
例如:
事情是這樣的:
class A(a : String, b : String) {
def this(s : List[Any]) = macro fromlist
}
應相當於是這樣的:
class A(a : String, b : String) {
def this(s : List[Any]) = this(s.head.toString, s.tail.head.toString)
}
僅僅使用了 「宏」關鍵字似乎沒有幫助。這是完全不允許在普通的斯卡拉?謝謝。
我想爲60+字段的case類創建裝飾器。 (我知道這聽起來更糟糕)。重載的應用程序沒有幫助,因爲裝飾對象必須是裝飾器的超類。 –