Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3283434
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:02:29+00:00 2026-05-17T20:02:29+00:00

How can I convert a java 1.4 Collection to a Scala Seq? I am

  • 0

How can I convert a java 1.4 Collection to a Scala Seq?

I am trying to pass a java-collection to a scala method:

import scala.collection.JavaConversions._

// list is a 1.4 java.util.ArrayList
// repository.getDir is Java legacy code
val list = repository.getDir(...)
perform(list)
def perform(entries: List[SVNDirEntry]) = ...

I always receive this error:

type mismatch; found : java.util.Collection[?0] where type ?0 required: List   
[SVNDirEntry]

So I guess I have to create the parameterized Sequence myself as Scala is only able to create an unparameterized Iterable?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:02:29+00:00Added an answer on May 17, 2026 at 8:02 pm

    First you have to make sure that list has the type java.util.List[SVNDirEntry]. To do this, use a cast:

    list.asInstanceOf[java.util.List[SVNDirEntry]]
    

    After that, the implicit conversion will be resolved for you if you import the JavaConversions object. An implicit conversion to a Scala sequence exists in the JavaConversions object. See the following example with a list of strings being passed to a method that expects a Scala sequence:

    scala> val jvlist: java.util.List[_] = new java.util.ArrayList[String]
    jvlist: java.util.List[_] = []
    
    scala> jvlist.asInstanceOf[java.util.List[String]]
    res0: java.util.List[String] = []
    
    scala> import collection.JavaConversions._                                                                          
    import collection.JavaConversions._                                                                                 
    
    scala> def perform(scalaseq: Seq[String]) = println("ok")                                    
    perform: (scalaseq: scala.collection.Seq[String])Unit                                                   
    
    scala> perform(res0)                                                                                                
    ok       
    

    These conversions do not copy the elements – they simply construct a wrapper around a Java collection. Both versions point to the same underlying data. Thus, there is no implicit conversion in JavaConversions to immutable Scala lists from mutable Java lists, because that would enable changing the contents of a Scala collection that is guaranteed to be immutable.

    In short – prefer Seq[...] to List[...] when defining parameters for methods if you can live with a less specific interface (as in perform above). Or write your own function that does the conversion by copying the elements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I convert my java program to an .exe file ?
Is there a tool out there that can automatically convert Python to Java? Can
Is there any free java library which I can use to convert string in
I'm trying to convert a project over to scala 2.8 from 2.7 and I've
Is there Java class or some sample code that can convert a java Date
Earlier I posted the following question: How can I convert this date in Java?
How can I convert a String to a Uri in Java (Android)? i.e.: String
How can I convert byte size into a human-readable format in Java? Like 1024
Is there a tool to convert javascript to java, so I can handle the
Somewhat related to How to convert XML to java.util.Map and vice versa , only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.