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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:32:46+00:00 2026-05-22T12:32:46+00:00

scala.math.ScalaNumber is a Java file which looks like this: public abstract class ScalaNumber extends

  • 0

scala.math.ScalaNumber is a Java file which looks like this:

public abstract class ScalaNumber extends java.lang.Number {
  protected abstract boolean isWhole();
  public abstract Object underlying();
}

And scala.math.BigDecimal implements it with:

class BigDecimal(val bigDecimal: BigDec, val mc: MathContext)
extends ScalaNumber with ScalaNumericConversions with Serializable {
  ...
  def underlying = bigDecimal
}

as well as scala.math.BigInt:

class BigInt(val bigInteger: BigInteger) extends ScalaNumber with ScalaNumericConversions with Serializable {
  ...
  def underlying = bigInteger
}

Confusingly, underlying is of type java.math.BigDecimal/java.math.BigInt instead of Object.

Do I miss something pretty obvious or is there something special-cased here?

EDIT: Of course I missed something obvious … You’re all right. Co-variant return types. Thanks!

  • 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-22T12:32:46+00:00Added an answer on May 22, 2026 at 12:32 pm

    It is simply a covariant return type, which is allowed both in Scala and Java.

    The rationale behind it is: if a class Base promises to return A form a certain method, then a subclass Derived <: Base respects the Liskov substitution principle if it returns A or any subclass B <: A. Certainly, if BigInt#underlying returns a BigInteger, this is no problem for clients of ScalaNumber, who may only hope for a plain Object.

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

Sidebar

Related Questions

Newbie Scala Question: Say I want to do this [Java code] in Scala: public
While playing around with regexps in Scala I wrote something like this: scala> val
I have an application where I would like to have mixed Java and Scala
This is an implementation for a leftist heap in Scala. package my.collections sealed abstract
I am a bit confused by this ArithmeticException. I have tried this on Scala
In Scala, does calling isEmtpy method on an instance of Stream class cause the
So I'm learning Scala at the moment, and I'm trying to create an abstract
I want to switch from Java to a scripting language for the Math based
Consider the following class written in Java: class NonNegativeDouble { private final double value;
Scala has a number of traits that you can use as type classes, for

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.