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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:04:29+00:00 2026-05-24T01:04:29+00:00

The following Scala declarations are OK: trait Base[B <: Base[B,M,ID], M <: Meta[B,M,ID], ID

  • 0

The following Scala declarations are OK:

trait Base[B <: Base[B,M,ID], M <: Meta[B,M,ID], ID <: Comparable[ID]] {
    // ...
}

trait Meta[B <: Base[B,M,ID], M <: Meta[B,M,ID], ID <: Comparable[ID]] extends Ordered[Meta[_,_,_]] {
    // ...
}

trait BaseWithID[B <: BaseWithID[B,M,ID], M <: Meta[B,M,ID], ID <: Comparable[ID]] extends Base[B,M,ID] with Ordered[B] {
    // ...
}


trait BaseWithIntID[B <: BaseWithIntID[B,M,ID], M <: MetaWithIntID[B,M,ID], ID <: Comparable[ID]] extends BaseWithID[B,M,ID] {
    // ...
}

trait MetaWithIntID[B <: BaseWithIntID[B,M,ID], M <: MetaWithIntID[B,M,ID], ID <: Comparable[ID]] extends Meta[B,M,ID] {
    // ...
}

But the following two are not:

trait BaseWithIntID[B <: BaseWithIntID[B,M], M <: MetaWithIntID[B,M]] extends BaseWithID[B,M,Int] {
    // ...
}

trait MetaWithIntID[B <: BaseWithIntID[B,M], M <: MetaWithIntID[B,M]] extends Meta[B,M,Int] {
    // ...
}

The difference is that I removed the ID type parameter in BaseWithIntID and MetaWithIntID, and specified Int explicitly in their respective base traits. But this does not compile, so does that mean that Int is not Comparable in Scala? If it is, what am I doing wrong? I tried Ordered instead of Comparable, and it made not difference.

I’m using Eclipse, and as usual, the error messages are unhelpful:

type arguments [B,M,Int] do not conform to trait BaseWithID's type parameter bounds [B <: BaseWithID[B,M,ID],M <: Meta[B,M,ID],ID <: java.lang.Comparable[ID]]

It just says that something is wrong, but not which type parameter is wrong, and why. Looking at this question, I thought I could try “ID <% Comparable[ID]” instead, but that is not legal in a trait declaration.

Actually, this does not work either (with the same error message):

trait TestBase extends BaseWithID[TestBase,TestMeta,Int]

trait TestMeta extends Meta[TestBase,TestMeta,Int]
  • 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-24T01:04:29+00:00Added an answer on May 24, 2026 at 1:04 am

    Int is indeed not comparable in scala, certainly because it is in fact implemented as java int, not java.lang.Integer. I’m not sure that would have been impossible, C# struct (value types) may implement interfaces, but this is not done here.

    What you usually do is say that there is an Ordering available in implicit scope for your ID type, with ID : Ordering.

    On a simple example:

    import Ordering.Implicits._
    def max[A : Ordering](x: A, y: A) : A = if (x > y) then x else y
    

    This amounts to passing an Ordering (which is the same thing as a java.util.Comparator) to the function. Indeed, the declaration

    def max[A : Ordering](x: A, y: A)
    

    translates to

    def max[A](x: A, y: A)(implicit ev: Ordering[A])
    

    where ev is a fresh name. If A : Ordering appears on class rather than method definition, as in your code, it translates to an implicit parameter to the constructor, that will be kept in a field if needed, and be available in implicit scope in the class. This is more flexible than forcing A to be Comparable (Ordered in scala) as it may be used on a class that is not yours and has not implemented Comparable. You can choose between different Odering on the same class too, if only by reversing the default one: there is a def reverse : Ordering method on Ordering which does just that.

    On the bad side, it is not likely the VM will be able to inline the call to the comparison method, but it was not likely either with an interface method in a generic.

    Types which implement Comparable<T> in java automatically get an Ordering in implicit scope by virtue of an implicit method (ordered) in object Ordering. A java Comparator<T> can also be converted to an Ordering (Ordering.comparatorToOrdering).

    importing Ordering.Implicits._ allows you the nice x > y syntax, when an Ordering[A] is in implicit scope.

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

Sidebar

Related Questions

If I have the following Scala type hierarchy: // Base traits trait TA[X <:
I have the following Scala code. import scala.actors.Actor object Alice extends Actor { this.start
Consider the following: scala> object Currency extends Enumeration { | type Currency = Value
If I have the following Scala code: trait BaseTrait[EnumType <: Enumeration] { protected val
I am trying to run the following scala code: println(world שלום) . but in
I have the following classes/traits in Scala trait Write[-T] { def add(elem : T);
Suppose I have the following Scala code: class Foo(a: Int) class Bar(b: Buffer[Int]) extends
Given the following Scala List: val l = List(List(a1, b1, c1), List(a2, b2, c2),
The following lines work when I enter them by hand on the Scala REPL
I am generating the scala AST using the following code: val setting = new

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.