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 3607662
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:24:14+00:00 2026-05-18T21:24:14+00:00

Can I use scala List in Java, like : import scala.collection.immutable.List; class HelloScalaList {

  • 0

Can I use scala List in Java, like :

import scala.collection.immutable.List;
class HelloScalaList {
    public static void main (String[] args) {
        List xs = List(1, 2, 3);
        System.out.println(xs);
    }
}

It does not seem to compile. can’t find List$.apply method.

when I change it to

List xs = Dir.ls()

where Dir is my scala class, and ls() returns a scala List, the compiler complaints about

“Internal compiler error: java.lang.ClassCastException: org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding
cannot be cast to org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding at
org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.initializeTypeVariable(BinaryTypeBinding.java:927)”

which I have no idea what it means.


I want to write some library in scala, but would also like it to be used in Java.

In my scala class there are methods that return scala List, for java code to use them, I have two options:

  1. use scala List in java directly

  2. write a wrapper class that returns java.util.List for those methods.

I’d rather like option 1, because otherwise I’ll have to write a wrapper class for nearly ALL my scala classes.

But I just can’t get scala List running in Java.

  • 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-18T21:24:14+00:00Added an answer on May 18, 2026 at 9:24 pm

    A little java-side helper method does the trick:

    import scala.collection.immutable.List;
    import scala.collection.immutable.List$;
    import scala.collection.immutable.$colon$colon;
    
    public class HelloScalaList {
    
        public static void main (String[] args) {
            List xs = list(1,2,3);
            System.out.println(xs);
        }
    
        public static <T> List<T> list(T ... ts) {
            List<T> result = List$.MODULE$.empty();
            for(int i = ts.length; i > 0; i--) {
                result = new $colon$colon(ts[i - 1], result);
            }
            return result;
        }
    }
    

    [Update]

    As a result of this question, I started a little project called “Scava” in order to support calls from Java to Scala: http://code.google.com/p/scava-org/

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

Sidebar

Related Questions

You can use more than one css class in an HTML tag in current
Using Scala 2.7.7: If I have a list of Options, I can flatten them
Everyone who's done any web application development in Scala knows that you can use
In Scala variance can be defined with variance operators like + and - on
I had a List of Scala tuples like the following: val l = List((1,2),(2,3),(3,4))
With WinForms, I can use Control.Scale to scale a control larger. When I do
You can use a standard dot notation or a method call in Objective-C to
I can use properties of an Excel Worksheet to tell if the worksheet is
You can use ftplib for full FTP support in Python. However the preferred way
You can use SelectFolder() to get a folder or GetOpenFolderitem(filter as string) to get

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.