[英]get java class for type tag of Scala case class
Using the type safe configuration and configs
( "com.github.kxbmap" %% "configs" % "0.4.4",
) library 使用类型安全配置和
configs
( "com.github.kxbmap" %% "configs" % "0.4.4",
)库
def loadConfiguration[T <: Product: TypeTag]: T = {
import configs.syntax._
val conf = ConfigFactory.load
conf.get[MyCaseClass]
should load the config, but fails as T is not a class
. 应该加载配置,但是由于
T is not a class
而失败。 How can I actually transform T
to fit for configs
as a java class? 我如何才能真正将
T
转换为适合Java类的configs
?
I'd suggest simply replacing TypeTag
with ClassTag
since you aren't using the TypeTag
.我建议简单地更换 TypeTag
与ClassTag
因为你没有使用TypeTag
。And if you were, you could combine them: T <: Product : TypeTag : ClassTag]
or use this solution: https://stackoverflow.com/a/18730004/9204如果是,则可以将它们组合在一起: T <: Product : TypeTag : ClassTag]
或使用以下解决方案: https T <: Product : TypeTag : ClassTag]
From the question I assumed "configs" could work given a Java Class
object (or a ClassTag
wrapping one). 从这个问题出发,我假设给定一个Java
Class
对象(或包装了ClassTag
对象),“ configs”就可以工作。 But after checking the documentation I see that it doesn't, so the above isn't relevant. 但是在检查了文档之后,我发现它没有,因此以上内容无关。
Instead you should use 相反,您应该使用
def loadConfiguration[T : Configs]: T = ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.