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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:17:13+00:00 2026-06-17T05:17:13+00:00

Say you have a method that takes a threshold and an input raises an

  • 0

Say you have a method that

  • takes a threshold and an input
  • raises an exception if the input is less than the threshold
  • otherwise returns the input

it would look something like this:

<N extends Number & Comparable<N>, S extends N> S ensureLessThan(N threshold, S input) {
    if (input.compareTo(threshold) >= 0) {
        throw new IllegalArgumentException("Input " + input + " is not less than " + threshold);
    }
    return input;
}

When run, this method throws a NoSuchMethodError:

Exception in thread "main" java.lang.NoSuchMethodError: java.lang.Number.compareTo(Ljava/lang/Object;)I

Adding what looks like a redundant cast makes it work:

...
    if (((N) input).compareTo(threshold) >= 0) {
...

So what’s going on here?

UPDATE: My Java version is

java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-11M3909)
Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)

And here’s a runnable example: https://gist.github.com/4526536

  • 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-17T05:17:15+00:00Added an answer on June 17, 2026 at 5:17 am

    I suspect it’s a bug in the compiler. It has staticly bound to Number.compareTo(Object) which doesn’t exist, when it should be Comparable.compareTo(Object).

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

Sidebar

Related Questions

Say I have a method that takes an int as a string and returns
Say I want to have a method that takes any kind of number, is
Let's say I have a method that takes a class, which is called like
Let's say I have a Player class. It has a Move method that takes
Let's say I have a method m() that takes an array of Strings as
Say I have a method that takes a CLLocationCoordinate2D. I can't pass nil directly
say, I have a generic command trait with an execute method that takes an
I have a method, say method1(), that takes a while to run. During it's
The instructions say: Create an equals method that takes an object reference and returns
Let's say I have a javascript method that takes a little to long to

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.