public
Last active — forked from Chouser/Ugly.java

  • Download Gist
Ugly.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
package mypkg;
 
public class Ugly {
public Ugly(){}
public String foo(boolean i) { return "bool: " + i; }
public String foo(Object o) { return "obj: " + o; }
}
 
user> (def u (foo.TestInterop2.))
#'user/u
 
;;; and obviously...
user> (let [t u]
(.foo t (boolean true)))
"obj: true"
use-ugly.clj
Clojure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
(.foo (mypkg.Ugly.) 5)
;=> "obj: 5"
 
(.foo (mypkg.Ugly.) true)
;=> "obj: true"
 
(.foo (mypkg.Ugly.) (boolean true))
;=> "bool: true"
 
 
(def u (mypkg.Ugly.))
(.foo u (boolean true))
;=> "obj: true"
 
(.foo #^mypkg.Ugly u (boolean true))
;=> "bool: true"
 
;; renamed mypkg.Ugly to foo.TestInterop2 when doing my tests
user> (let [t (foo.TestInterop2.)]
(.foo t (boolean true)))
"bool: true"
 
;;; type-hinting the Var
user> (def #^foo.TestInterop2 x (foo.TestInterop2.))
#'user/x
user> (.foo x (boolean true))
"bool: true"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.