Skip to content

Instantly share code, notes, and snippets.

@qbg
Created October 22, 2010 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qbg/640760 to your computer and use it in GitHub Desktop.
Save qbg/640760 to your computer and use it in GitHub Desktop.
Primitive fn error
user=> (import 'java.util.ArrayList)
java.util.ArrayList
user=> (defn foo ^ArrayList [^double n] (doto (ArrayList.) (.add (* n 2))))
#'user/foo
user=> (defn bar [x] (let [al (foo x)] (+ x (.get al 0))))
#'user/bar
user=> (bar 5)
AbstractMethodError user$foo.invokePrim(D)Ljava/lang/Object; user/bar (NO_SOURCE_FILE:5)
@qbg
Copy link
Author

qbg commented Oct 22, 2010

The problem is from the ArrayList type hint; if you remove it, then it works:

user=> (defn foo [^double n](doto %28ArrayList.%29 %28.add %28* n 2%29%29))

'user/foo

user=> (defn bar [x](let [al %28foo x%29] %28+ x %28.get al 0%29%29))

'user/bar

user=> (bar 5)
15.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment