Getting at an Unsafe
instance involves overcoming some access restrictions. The simplest way is to use reflection; see the Java Magic. Part 4: sun.misc.Unsafe blog post by Mykhailo Kozik for a description of this and other methods. Here's a Clojure snippet which does just that:
(let [f (.getDeclaredField sun.misc.Unsafe "theUnsafe")]
(.setAccessible f true)
(.get f nil))
;= #<Unsafe sun.misc.Unsafe@63124f52>
As pointed out by acomar and WolfeFan, getClass
is not a static method -- it's an instance method declared by Object
and therefore available on all objects:
(.getClass the-unsafe) ; the-unsafe obtained as above
;= sun.misc.Unsafe
As for the actual question, (Foo/meth)
is the correct syntax for a no-argument static method call in Clojure.