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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:08:48+00:00 2026-06-11T22:08:48+00:00

This behavior makes no sense to me: user=> (type 1) java.lang.Long user=> (type (cast

  • 0

This behavior makes no sense to me:

user=> (type 1)
java.lang.Long
user=> (type (cast Long 1))
java.lang.Long
user=> (type 1)
java.lang.Long
user=> (type (Long. 1))
java.lang.Long
user=> (type (cast Long 1))
java.lang.Long
user=> (BigDecimal. 1)
1M
user=> (BigDecimal. (Long. 1))
CompilerException java.lang.IllegalArgumentException: More than one matching method found: java.math.BigDecimal, compiling:(NO_SOURCE_PATH:22) 
user=> (BigDecimal. (cast Long 1))
1M

Why does the (BigDecimal. (Long. 1)) case fail to find an unambiguous matching method signature while the other two expressions—which have exactly the same argument type—succeed?


Update:

What I find even more strange about this behavior is that it seems particular to the Long type:

user=> (BigDecimal. (Long. 1))
CompilerException java.lang.IllegalArgumentException: More than one matching method found: java.math.BigDecimal, compiling:(NO_SOURCE_PATH:1) 
user=> (BigDecimal. (Integer. 1))
1M
  • 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-11T22:08:49+00:00Added an answer on June 11, 2026 at 10:08 pm

    From this discussion on the Clojure discussion group it seems you have encountered a design decision made by Rich Hickey. Specifically, because BigDecimal does not have a constructor of the signature BigDecimal(Long long) (Edit: and therefore leaves the compiler having to choose between the int and long constructors – see comments below for discussion on why using Integer works), the compiler will not attempt to “guess” which constructor you will meant, and explicitly fails.

    The bottom line is specific type requirements on the Java side require explicit boxing on order to have correct and non-brittle code. – Rich Hickey

    Note that literals are parsed as primitives, not “boxed” types, per this documentation:

    In contrast to previous versions of Clojure, numeric literals are parsed as primitive longs or doubles.

    To understand why the other operations work, you have to dig into Clojure source, specifically Compiler.java and its inner class NumberExpr. That is the where your literal gets auto-boxed to a Long and the compiler has no problem in turn calling Object.getClass() (which both type and class do).

    In the Compiler.getMatchingParams(), the Clojure compiler attempts to resolve which constructor of BigDecimal to use. However, you have explicitly specified that your parameter has the type Long – there is no constructor for BigDecimal that takes that type.

    Maybe this isn’t “common sense,” but Rich Hickey made the decision that you need to be precise about the type of your parameters and that they have to match the type of the Java class. The compiler is refusing to guess your intent.

    Note the following:

    user=> (new BigDecimal 1M)
    Reflection warning, NO_SOURCE_PATH:33 - call to java.math.BigDecimal ctor can't be resolved.
    IllegalArgumentException No matching ctor found for class java.math.BigDecimal  clojure.lang.Reflector.invokeConstructor (Reflector.java:183)
    

    Also note that this Java code is valid and resolves to the int constructor for BigDecimal:

        byte b = 1;
        new BigDecimal(new Byte(b));
    

    But this code also fails (even though it “should” use the int constructor):

    user=> (BigDecimal. (Byte. (byte 1)))
    Reflection warning, NO_SOURCE_PATH:37 - call to java.math.BigDecimal ctor can't be resolved.
    IllegalArgumentException No matching ctor found for class java.math.BigDecimal  clojure.lang.Reflector.invokeConstructor (Reflector.java:183)
    

    tl;dr: Clojure supports Java interop but that does not mean it has to follow the promotion rules of Java Language Specification.

    What about cast?

    A comment below asks about (cast). In that case you are explicitly telling the Clojure compiler to delegate type resolution to the JVM. Note the following (nonsensical) code that compiles, yet fails at runtime:

    user=> (set! *warn-on-reflection* true)
    true
    user=> (defn make-big-dec [obj] (BigDecimal. (cast Math obj)))
    Reflection warning, NO_SOURCE_PATH:7 - call to java.math.BigDecimal ctor can't be resolved.
    #'user/make-big-dec
    user=> (make-big-dec 1)
    ClassCastException   java.lang.Class.cast (Class.java:2990)
    

    Epilogue II

    There has been quite a bit of discussion on this topic in the Clojure community. Please check out these detailed threads:

    Enhanced Primitive Support (Rich Hickey)

    Clojure 1.3 treatment of integers and longs (Nathan Marz)

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

Sidebar

Related Questions

Hopefully this makes sense - my html is as follows html <a href=# class=someclass>An
I don't understand this behavior in javascript for inheritance I've always seen it defined
I've had this behavior happen to me twice recently and I was wondering what
What I want is this behavior: class a: list = [] x = a()
I get this behavior in both Chrome (Developer Tools) and Firefox (Firebug). Note the
I am struggling really hard to understand this behavior so maybe someone can shed
I would like to have this behavior in a task history stack: First task
I'd like to understand the reason for this behavior of OCAML objects. Suppose I
I don't know the exact words to describe this behavior in the following pages:
I have searched but could not find the reason for this behavior. I have

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.