Scala reflection and Squeryl

心已入冬 提交于 2019-12-06 16:15:19

It's not really a Squeryl thing. As I understand it, the problem is that the pattern match testing is done at runtime, after type erasure has occurred. Scala is able to keep the type information around with the TypeTag and perform the runtime check but it can't infer that the types are correct at compile time. If you were to try something like

case t: ClassTag[User] => users

Which is asking the compiler to do a static check, you would get a warning that the User type is erased. The way you are doing it should work since it should be fine to perform the cast after you've verified the type, and I don't think there is a better way.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!