简体   繁体   English

如何使用无形中的变量访问案例类字段

[英]How to access case class fields using a variable in shapeless

I want to do something like this我想做这样的事情

case class Dog(name :String, breed : String)

val dg = Dog("ABC", "Husky")

At run time I want to get the case class field value through a variable Below, "name" would be dynamically calculated driven from another input在运行时,我想通过变量获取案例类字段值 下面, "name"将根据另一个输入动态计算

val str = "'" + "name"
val witn = Witness(Symbol(str))

It fails with Expression表达式失败

scala.Symbol.apply(str) does not evaluate to a constant or a stable value scala.Symbol.apply(str) 不计算为常数或稳定值

I am not sure how this should be resolved.我不确定这应该如何解决。 If it can be resolved如果可以解决

Appreciate all help!感谢所有帮助!

Thanks!谢谢!

Using `String` instead of `Symbol` in `LabelledGeneric` etc 在“LabelledGeneric”等中使用“String”代替“Symbol”

Guess it has been asked and answered above.猜猜上面已经问过并回答过。 there is no support for String yet.尚不支持 String。 Waiting for the release that has it!等待有它的发布!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM