[英]Is there in scala the equivalent of the c# nameof?
在c#中,我可以編寫這樣的代碼(我運行它Linqpad 5):
void Main()
{
new Test { Property1 = 100 }.Dump();
Console.WriteLine(nameof(Test.Property1));
}
class Test
{
public int Property1 { get; set; }
override public String ToString()
{
return $"{nameof(Property1)}={Property1}";
}
}
是否有scala相當於nameof?
謝謝
在Scala中,它可以由(宏)庫完成,而不需要特殊的語言級支持。 https://github.com/dwickern/scala-nameof上有一個。
在Scala和C#中沒有任何類似的方法,如果你真的想要這個函數,你可以使用scala-reflection 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.