views:

115

answers:

1

I'm trying to write a function to play a sound file once, using some resources I found. The code is as follows:

(defn play [file]
  (let [songp (URL. (.getCodeBase) file)
    song (.newAudioClip songp)]
    (. song play)))

The problem is, (.getCodeBase) is a malformed member expression. I'm not sure what to do. How do you call a method like this? In the Java code I looked at, it was simply called like so:

getCodeBase()

Am I missing something?

+4  A: 

.getCodeBase is an instance method call, and as such requires a receiver (what goes before the dot in Java). If your Java code was just getCodeBase(), then there are two possibilities: either it actually means this.getCodeBase(), in which case you should figure out what this was in that method, and specify it as the first argument:

(.getCodeBase obj)

Or, it could be a static method of that class (or one of its base classes), in which case you should use a static method invocation expression instead:

(ClassName/getCodeBase)

Posting the Java code that you're trying to translate, with sufficient context, would probably help answer this in more detail.

Pavel Minaev