在 Clojure 中调用 getCodeBase 时遇到问题
我正在尝试使用我找到的一些资源编写一个函数来播放一次声音文件。 代码如下:
(defn play [file] (let [songp (URL. (.getCodeBase) file) song (.newAudioClip songp)] (. song play)))
问题是,(.getCodeBase) 是一个格式错误的成员表达式。 我不知道该怎么办。 你如何调用这样的方法? 在我查看的 Java 代码中,它的调用方式很简单:
getCodeBase()
我错过了什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.getCodeBase
是一个实例方法调用,因此需要一个接收器(Java 中点之前的内容)。 如果您的 Java 代码只是getCodeBase()
,那么有两种可能性:要么它实际上意味着this.getCodeBase()
,在这种情况下您应该弄清楚>this
在该方法中,并将其指定为第一个参数:或者,它可能是该类(或其基类之一)的静态方法,在这种情况下,您应该使用静态方法调用表达式相反:
发布您尝试翻译的 Java 代码,并提供足够的上下文,可能有助于更详细地回答这个问题。
.getCodeBase
is an instance method call, and as such requires a receiver (what goes before the dot in Java). If your Java code was justgetCodeBase()
, then there are two possibilities: either it actually meansthis.getCodeBase()
, in which case you should figure out whatthis
was in that method, and specify it as the first argument: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:
Posting the Java code that you're trying to translate, with sufficient context, would probably help answer this in more detail.