Created
October 22, 2010 15:29
-
-
Save qbg/640760 to your computer and use it in GitHub Desktop.
Primitive fn error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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