Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a Scala from Java Play Framework which takes a ClassTag

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 );
like image 734
Shawn Vader Avatar asked Feb 05 '14 15:02

Shawn Vader


1 Answers

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).

like image 160
Adam Crume Avatar answered Nov 03 '22 09:11

Adam Crume