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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:06:39+00:00 2026-05-20T18:06:39+00:00

I am having issues with the following code in Scala import org.junit.Test import org.junit.Assert._

  • 0

I am having issues with the following code in Scala

import org.junit.Test
import org.junit.Assert._

class BoxingTest {

    val holder: Holder[Integer] = new Holder[Integer]();

    @Test
    def Holder_Eq_Primitive(){        
        assertEquals(holder, holder eq 1);
    }

    @Test
    def Holder_Eq_Boxed(){        
        assertEquals(holder, holder eq 1.asInstanceOf[Integer]);
    }

}

class Holder[T] {

    def eq(other: T): Holder[_] = this;
}

I get the following error in compilation

/BoxingTest.scala:12: error: type mismatch;
[INFO]  found   : Int
[INFO]  required: AnyRef
[INFO] Note: primitive types are not implicitly converted to AnyRef.
[INFO] You can safely force boxing by casting x.asInstanceOf[AnyRef].
[INFO]         assertEquals(holder, holder eq 1);
[INFO]                                     ^
[ERROR] one error found
[INFO] -------------------------

Why doesn’t the implicit conversion from Int to Integer handle the issue?

I could easily fix the code by not using eq, but this just doesn’t seem right. IMHO the available implicit conversions should be applied here.

UPDATE

I got the issue fixed by using the signature like this

import org.junit.Test
import org.junit.Assert._

class BoxingTest {

    @Test
    def Holder_Eq_Primitive(){
        val holder: Holder[Int] = new Holder[Int]();
        assertEquals(holder, holder eq 1);
    }

    @Test
    def Holder_Eq_Boxed(){
        val holder: Holder[Integer] = new Holder[Integer]();
        assertEquals(holder, holder eq 1.asInstanceOf[Integer]);
    }

}

class Holder[T] {

    def eq(other: T): Holder[_] = ...;
}

Still, it would be good to use the wrapper types instead.

  • 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-20T18:06:40+00:00Added an answer on May 20, 2026 at 6:06 pm

    I tried comparing an Int value against integer literal and got some interesting note from the compiler. This may shed some light about the causes of this behaviour.

    scala> val a = 1
    scala> a eq 1
    <console>:6: error: type mismatch;
     found   : Int
     required: ?{val eq: ?}
    Note that implicit conversions are not applicable because they are ambiguous:
     both method int2Integer in object Predef of type (Int)java.lang.Integer
     and method intWrapper in object Predef of type (Int)scala.runtime.RichInt
     are possible conversion functions from Int to ?{val eq: ?}
           a eq 1
           ^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having issues with the following code, where I use a JComboBox to change
I'm having an issue with the following code: private void DataPortal_Fetch(TaskCriteria criteria) { using
Ok. I'm having an issue with the following bit of code: StreamReader arrComputer =
I'm having issues getting Firefox to update a webpage when its class is changed
When I try and compile the following code... #include <vector> template <class T> void
After following the official tutorial here: tutorial I'm still having issues adding rows/creating a
I'm following the following blog list below and I'm having issues getting paperclip 2.3.6
I have the following application which replicates an issue I'm having in a larger
I'm having issues with my SQL Reporting Services reports. I'm using a custom font
I'm having issues creating an ActionLink using Preview 5. All the docs I can

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.