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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:17:17+00:00 2026-05-28T00:17:17+00:00

If I define the following function which expects a Long, and I define the

  • 0

If I define the following function which expects a Long, and I define the following implicit function, the implicit function is used when I pass a Date to the first function and everything works as expected:

def millisToDays(in: Long): Int = (in / (1000L * 3600L * 24L)).toInt
implicit def dateToLong(d: Date) = d.getTime
println(millisToDays(new Date))

But for the following second example, I get a compiler error on the third line: “inferred type arguments [Int] do not conform to method mySum’s type parameter bounds [t <: java.lang.Number]”

def mySum[T <: Number](as: T*): Double = as.foldLeft(0d)(_ + _.doubleValue)
implicit def intToInteger(n: Int): Integer = new Integer(n.toInt)
var r = mySum(2, 3)

What have I done wrong? Why isn’t the intToInteger implicit function being used?

I am guessing that the problem is that the implicit function does not return a “T <: Number”, but rather an Integer, so the compiler can’t guess that the implicit function is actually useful.

Is there anyway which I can give the compiler a hint that it should use the implicit function?

Thanks!
Ant

  • 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-28T00:17:17+00:00Added an answer on May 28, 2026 at 12:17 am

    The [T <: Number] type bounds means that T must be a subtype of Number. The implicit conversion from Int to Integer doesn’t give you this, since even though the conversion is available it still doesn’t mean that Int is a subtype of Number.

    Luckily, there is something similar called view bounds, written [T <% Number], which specifies exactly what you want, that there is an implicit conversion available from T to Number

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

Sidebar

Related Questions

I want to define a following function: if(stmtToFinalize) { NSLog(@Finalizing statement stmtToFinalize); if (sqlite3_finalize(stmtToFinalize)
I want to define a constant in objective-c. Previously I had the following function:
The following code works fine #define open { #define close } #include<stdio.h> #define int
I've used following function in some of my projects, but recently I've created a
as expected it invokes the function foo the first time, but when i want
I have the following function which updates a time_remaining span on the page. function
I have the following function defined inside my linked list class. The declaration in
I wish to define the following typeclass Mapping : {-# LANGUAGE MultiParamTypeClasses #-} class
I have the following items (define itemslist (list 'a1 'b2 'c3 (list 'z1 'z2)
For instance, is the following possible: #define definer(x) #define #x?

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.