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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:22:37+00:00 2026-06-03T13:22:37+00:00

Working in Scala-IDE, I have a Java library, in which one of the methods

  • 0

Working in Scala-IDE, I have a Java library, in which one of the methods receives java.lang.Object. And I want to map a list of Int values to it. The only solution that works is:

val listOfInts = groupOfObjects.map(_.getNeededInt)

for(int <- listOfInts) libraryObject.libraryMethod(int)

while the following one:

groupOfObjects.map(_.getNeededInt).map(libraryMethod(_)

and even

val listOfInts = groupOfObjects.map(_.getNeededInt)

val result = listOfInts.map(libraryObject.libraryMethod(_))

say

type mismatch; found : Int required: java.lang.Object Note: an
implicit exists from scala.Int => java.lang.Integer, but methods
inherited from Object are rendered ambiguous. This is to avoid a
blanket implicit which would convert any scala.Int to any AnyRef. You
may wish to use a type ascription: x: java.lang.Integer.

and something like

val result = listOfInts.map(libraryObject.libraryMethod(x => x.toInt))

or

val result = listOfInts.map(libraryObject.libraryMethod(_.toInt))

does not work also.

1) Why is it happening? As far as I know, the for and map routines do not differ that much!

2) Also: what means You may wish to use a type ascription: x: java.lang.Integer? How would I do that? I tried designating the type explicitly, like x: Int => x.toInt, but that is too erroneus. So what is the “type ascription”?

UPDATE:

The solution proposed by T.Grottker, adds to it. The error that I am getting with it is this:

  • missing parameter type for expanded function ((x$3) => x$3.asInstanceOf[java.lang.Object])
  • missing parameter type for expanded function ((x$3) => x$3.asInstanceOf{#null#}[java.lang.Object]{#null#}) {#null#}

and I’m like, OMG, it just grows! Who can explain what all these <null> things mean here? I just want to know the truth. (NOTE: I had to replace <> brakets with # because the SO engine cut out the whole thing then, so use your imagination to replace them back).

  • 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-03T13:22:39+00:00Added an answer on June 3, 2026 at 1:22 pm

    The type mismatch tells you exactly the problem: you can convert to java.lang.Integer but not to java.lang.Object. So tell it you want to ask for an Integer somewhere along the way. For example:

    groupOfObjects.map(_.getNeededInt: java.lang.Integer).map(libraryObject.libraryMethod(_))
    

    (The notation value: Type–when used outside of the declaration of a val or var or parameter method–means to view value as that type, if possible; value either needs to be a subclass of Type, or there needs to be an implicit conversion that can convert value into something of the appropriate type.)

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

Sidebar

Related Questions

When working with Java from Scala, we have to account for null. HttpServletRequest getters
I installed Scala IDE for Eclipse , and it seems to be working okay.
Should be an easy one. I'm working on Scala trying to handle long sequences
I have been working on a project in scala, but I am getting some
Im currently working with two actors in scala. One, the producer , produces some
I am working on a simple project in Eclipse in Scala-IDE. The project makes
I’m working on a Scala script which uses Joda Time. Up until today, this
I'm working on a Scala API (for Twilio, by the way) where operations have
I am working on a small Scala project. I have the following issue with
I'm working with a map in Scala and doing the usual if there's no

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.