Calling a Scala from Java Play Framework which takes a ClassTag

白昼怎懂夜的黑 提交于 2020-01-02 00:53:28

问题


I am trying to make a call from a Play Java class to a Scala method which takes a ClassTag as a parameter

My failing attempt is

 Option<LocalUser> localUser = Cache.getAs(userId.userId(), app, new ClassTag<LocalUser>() );

The API method looks like this

Cache.getAs(String key, Application app, ClassTag<LocalUser> ct );

回答1:


I had the same issue when calling a different Scala API from Java. You'd use:

ClassTag<LocalUser> tag = scala.reflect.ClassTag$.MODULE$.apply(LocalUser.class);

I'm not sure why Scala requires another class and a static object, but I think this is essentially the equivalent of a static method ClassTag.apply(Class).



来源:https://stackoverflow.com/questions/21582045/calling-a-scala-from-java-play-framework-which-takes-a-classtag

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