Play 2.4 - Can't convert a java Set to a Scala.collection.immutable.Set

633 views
Skip to first unread message

Tiago Lourenço

unread,
Oct 15, 2014, 12:54:21 PM10/15/14
to play-fr...@googlegroups.com
I'm new in play and I'm following the book "Play for Java MEAP v2". 

I'm stuck in page 48, where a can't convert a java Set to a Scala.collection.immutable.Set, I have the follow error: 


" render(scala.collection.immutable.list<models.Product>) in canot be applied to java.util.list<models.Product>"


I need help please :)

amertum

unread,
Oct 15, 2014, 5:22:06 PM10/15/14
to play-fr...@googlegroups.com
For mutable collection, you can use the class scala.collection.JavaConverters which have methods like asScalaSetConverter.
For immutable collection, there is also the play class play.libs.Scala.
Class as scala.collection.immutable.Set$.MODULE provide methods to create immutable Set. Following this pattern, the class scala.collection.immutable.Map$.MODULE exists also.

This is the bad side of integrating Scala into Java. It is easier the other way.

Tiago Lourenço

unread,
Oct 15, 2014, 7:20:05 PM10/15/14
to play-fr...@googlegroups.com

Can give me one example more specific, please 


> --
> You received this message because you are subscribed to a topic in the Google Groups "play-framework" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/play-framework/l54Ei_Cghos/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to play-framewor...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

ludo amertum

unread,
Oct 16, 2014, 4:18:38 AM10/16/14
to play-fr...@googlegroups.com
java.util.Set<String> javaSet = new java.util.HashSet<>();
scala.collection.mutable.Set<String> mutableScalaSet = scala.collection.JavaConverters.asScalaSetConverter(javaSet).asScala();
scala.collection.immutable.Set<String> immutableScalaSet = mutableScalaSet.toSet();

Tiago Lourenço

unread,
Oct 16, 2014, 3:56:05 PM10/16/14
to play-fr...@googlegroups.com
Thanks, very much :) amertum


Tiago Lourenço

unread,
Oct 18, 2014, 6:38:53 AM10/18/14
to play-fr...@googlegroups.com
Hi, 

I have the follow problem:

" render(play.api.Data.Form<models.Product>) in canot be applied to play.Data.Form<models.Product>"

How can I resolve this????

Pablo Fernandez

unread,
Oct 20, 2014, 6:29:20 PM10/20/14
to play-fr...@googlegroups.com
Can you give us more context? Usually when you have a play.api.Something and play.Something mismatch it has to do with a Java/Scala incompatibility.

Joining the dots with your initial question... perhaps you're configuring your play project to be a Java project and using Scala? 
Reply all
Reply to author
Forward
0 new messages