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

  • Home
  • SEARCH
  • 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 8863367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:57:39+00:00 2026-06-14T15:57:39+00:00

I have two Java classes: LogEntry and Record . The LogEntry class has a

  • 0

I have two Java classes: LogEntry and Record.

The LogEntry class has a method shown below:

public LogEntry setRec(List<Map<String,List<Record>>> rec) 

In Scala I try to put Record into LogEntry like this:

import scala.collection.JavaConversions._
import collection.mutable._
val log = new LogEntry()
val rec = new Record()

val map:java.util.Map[String, java.util.List[Record]] = HashMap("sessionKey" -> ArrayBuffer(rec))
log.setRec(List(map))

But I got a compile error:

scala> val map:java.util.Map[String, java.util.List[Record]] = HashMap("sessionKey" -> ArrayBuffer(eventPart))
<console>:14: error: type mismatch;
 found   : scala.collection.mutable.HashMap[String,scala.collection.mutable.ArrayBuffer[Record]]
 required: java.util.Map[String,java.util.List[Record]]
       val map:java.util.Map[String, java.util.List[Record]] = HashMap("sessionKey" -> ArrayBuffer(eventPart))
                                                                      ^

Seems that the auto convention from Scala collection to Java collection failed, but as described in the official doc :

mutable.Buffer   <=>     java.util.List   
mutable.Map     <=>     java.util.Map

scala> val jul: java.util.List[Int] = ArrayBuffer(1, 2, 3)   
jul: java.util.List[Int] = [1, 2, 3]   

scala> val m: java.util.Map[String, Int] = HashMap("abc" -> 1, "hello" -> 2)   
m: java.util.Map[String,Int] = {hello=2, abc=1}

ArrayBuffer can be convert to java.util.List and HashMap can be convert to java.util.Map.

So, why this error occurred?

  • 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-06-14T15:57:40+00:00Added an answer on June 14, 2026 at 3:57 pm

    The implicit conversions don’t apply to type parameters (though you can use view bounds to simulate it). That is, if you have implicit conversion from Foo to Bar, values of type Foo can be used where Bar is needed:

    val foo: Foo = ...
    def bar(b: Bar) = ...
    bar(foo)
    

    but (e.g.) Seq[Foo] can’t be used instead of Seq[Bar]:

    val foo: Foo = ...
    def bar(list: Seq[Bar]) = ...
    bar(Seq(foo)) // type error
    

    That’s why conversion between ArrayBuffer and java.util.List can’t be used there.

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

Sidebar

Related Questions

I have two Java-Classes as follows: public class MyClass { ... } public class
I have two of the following java classes (listed below) Class BookInfo declares static
In Java I have two classes: Class A { public String ID; public Object
I have the following two classes: import java.io.*; import java.util.*; public class User {
I have two java classes as follows App1 without a package: class App1 {
I'm making a shopping list mobile application (Java ME) and i have two classes;
Actually I have two java classes of which one is an activity class. Now
I have two Java classes: B, which extends another class A, as follows :
Suppose I have two classes deriving from a third abstract class: public abstract class
I have two java classes. Schedule is the main class that uses an array

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.