Home > Java Util Arraylist Cannot > Java.util.arraylist Cannot Be Cast To Scala.collection.immutable.list

Java.util.arraylist Cannot Be Cast To Scala.collection.immutable.list

share|improve this answer edited Sep 15 '11 at 18:43 answered Oct 19 '10 at 14:49 robinst 15.8k55470 Works like a charm almost every time! –Jay Taylor Jul 18 '11 And If I change the implicit conversion ScPlantComponentScListToJList to java.util.Arrays.asList(x.toArray: _*) as desciped here http://stubbisms.wordpress.com/2009/02/18/fighting-scala-scala-to-java-l... Also, it seems that the last two lines could be combined to a single line list.asScala.toList –redent84 Oct 20 '14 at 16:38 the first var list will get java I'll give it a bit more time since I'd prefer to avoid using JavaConverters if there's a better approach in play!. weblink

In particular, the Scala libraries put much more emphasis on immutable collections, and provide many more operations that transform a collection into a new one. Subscribed! Your response reminded me of this function :)Thanks for the hint, my mind has been seriously damage from doing way too much Java work in the past. :) The Under-Appreciated Unfold In your case, to convert a java.util.List to Scala List you can do this: val list = new java.util.ArrayList[java.lang.String] list.add("A") list.add("B") list.asScala share|improve this answer answered May 12 '10 at 18:47 http://stackoverflow.com/questions/674713/converting-a-java-collection-into-a-scala-collection

In it, you'll get: The week's top questions and answers Important community announcements Questions that need answers see an example newsletter By subscribing, you agree to the privacy policy and terms I thought List( (for...)) would create a List with the entries of the for-comprehension. How to reply? Linked 147 What is the difference between JavaConverters and JavaConversions in Scala? 85 How to get Scala List from Java List? 9 Scala equivalent of new HashSet(Collection) 1 Convert Java List

But I have no doubt that there are> other ways.>> Cheers,> -V>> On Feb 19, 2008 3:30 PM, Jan Kriesten <[hidden email]> wrote: >>> Hi,>>>> is there a better way to Jetzt freischalten unter http://movieflat.web.de Top Login or register to post comments Wed, 2010-03-17, 20:47 #3 Seth Tisue Joined: 2008-12-16, Re: trouble with implicit type conversion >>>>> "Lothar" == Lothar Krenzien writes: On the one hand, it saves you explicitly casting every List[String] which comes out of iBatis, though it also delegates potential errors that the compiler would pick up at compile time Thanks!

Thanks for your help. Hope this helps, Jon -- Jon Pretty | Sygneca Ltd. Washington DC odd tour request issue more hot questions question feed lang-scala about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Here's my scala code: > > import java.util.{List => JList} > import scala.collection.{JavaConversions => JConversions}; > > //automatically convert a scala.List to a java.util.List >  implicit def ScPlantComponentScListToJList(x:scala.List[PlantComponent[_]]) = java.util.Arrays.asList(x.toArray) >

What is a Rotary Club Word™? Ah - I see. Are there still systems around with a /bin/sh binary? What does "there lived here then" mean?

Hot Network Questions What is the most someone can lose the popular vote by but still win the electoral college? http://scala-language.1934581.n4.nabble.com/java-util-ArrayList-to-List-td1938067.html Though I still prefer them, as IMHO the names are more appropriate. http://produkte.web.de/go/02/ Top Login or register to post comments Wed, 2010-03-17, 18:07 #1 Lex Joined: 2010-02-28, Re: trouble with implicit type conversion I have tried to answer the question too but quickly What do I do?

blog comments powered by Disqus Contents Introduction Mutable and Immutable Collections Trait Traversable Trait Iterable The sequence traits Seq, IndexedSeq, and LinearSeq Sets Maps Concrete Immutable Collection Classes Concrete Mutable Collection have a peek at these guys I am actually trying to convert a Java API call to Spring's SimpleJdbcTemplate, which returns a java.util.List, into a Scala immutable HashSet. share|improve this answer edited Sep 8 '13 at 19:10 Erik Allik 18.9k65271 answered Mar 24 '09 at 7:51 Jorge Ortiz 4,1041321 9 This suggestion doesn't work where I want to A guy scammed me, but he gave me a bank account number & routing number.

Certain other Scala collections can also be converted to Java, but do not have a conversion back to the original Scala type: Seq => java.util.List mutable.Seq => java.util.List Set => java.util.Set I wasn't exactly thinking too hard at that moment, and didn't realize it was actually a Java List until I tried to use the foreach method on it, and Eclipse balked For instance, you might want to access an existing Java collection as if it were a Scala collection. check over here Jon Pretty Reply | Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Re: ClassCastException - was: java.util.ArrayList to List?

Check if an item is in a nested list Mimsy were the Borogoves - why is "mimsy" an adjective? up vote 1 down vote try below in your template code : @import java.util @(scripts: util.List[String]) share|improve this answer answered Sep 26 '15 at 12:14 saral 212 add a comment| Your Jon Pretty Reply | Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Re: ClassCastException - was: java.util.ArrayList to List?

In reply to this post by Martin Odersky Hi Jan, It looks like there are a couple of problems: Jan Kriesten wrote: > after some evaluation, I thought I'd have a

a sequence) and allows, among other things, random access to its elements. Does Intel sell CPUs in ribbons? It is quite easy to do this, because Scala offers implicit conversions between all the major collection types in the JavaConverters object. This page is no longer maintained — Please continue to the home page at www.scala-lang.org Search this site: Scala Main Menu About ScalaIntroduction In the Enterprise Scala CommunityMailing Listsscala scala-announce scala-user

In particular, you will find bidirectional conversions between the following types. Homepage Subject Comment About text formats Anonymous format Allowed HTML tags:

    1.  Lines and paragraphs break automatically. Most of the methods mentioned on the internet just convert the (eg) java.util.List[java.lang.Long] to scala.collection.immutable.List[java.lang.Long]. this content current community chat Stack Overflow Meta Stack Overflow your communities Sign up or log in to customize your list. 

      Graham mentions several interesting points in that article, including these notes: If we look a bit further into the Scala API, we'll see that there's also a trait called Seq, which Can Trump undo the UN climate change agreement? Back to top Conversions between Java and Scala collections with JavaConversions While I'm on this topic, I'll conclude with a few links to the Scala website, where you can find more J.java > ~> > >The Java code shown has the full type, not the raw type, but compilation >succeeds. > Top Login or register to post comments Wed, 2010-03-17, 21:57 #8

      All rights reserved. So the alternate imports here seem to be only aliases. Lothar -----Ursprüngliche Nachricht----- Von: Lex Gesendet: 17.03.2010 18:04:02 An: Lothar Krenzien Betreff: Re: [scala-user] trouble with implicit type conversion >I have tried to answer the question too but quickly changed my Greetings Jan,I might be wrong here, but since ArrayList is a mutable construct, and List is an immutable construct (I am assuming you're not referring to java.util.List)you could just iterate over

      more stack exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed Top Login or register to post comments Wed, 2010-03-17, 21:47 #7 merlin-hst Joined: 2009-10-14, Re: trouble with implicit type conversion That's right, it works basically. Check with this (Using 2.7.0-RC2) snippet: > > scala> implicit def List2StringList( list: List[_] ): List[String] = > list.asInstanceOf[List[String]] > List2StringList: (List[_$1] forSome { type _$1 })List[String] > > scala> val The worst things about Presidential candidates in history Add new comment Your name Email The content of this field is kept private and will not be shown publicly.

© Copyright 2017 pgexch.com. All rights reserved.