从Scala访问公共静态Java方法 [英] Accessing public static java method from scala
问题描述
我正在尝试在此处使用Java facebook库 http://restfb.com/#publishing 在scala play2应用程序中,但是当尝试调用下面的静态with
方法时,它给了我"Compliation Error [期望的标识符,但找到了'with'.]".
I'm trying to use the Java facebook library here http://restfb.com/#publishing in a scala play2 app, but when trying to call the static with
methods below, it gives me "Compliation Error [identifier expected but 'with' found.]".
val fbClass = classOf[FacebookType]
val param = Parameter.with("message", msg)
val attachment = BinaryAttachment.with("cat.png", stream)
val fbResp = facebookClient.publish("me/photos", fbClass, attachment, param)
我看到尝试调用受保护的静态方法时遇到问题,但是这些方法被定义为公共方法,如源.我在做错什么吗?
I see that there is an issue trying to invoke protected static methods, but these are defined as public, as can be seen in the javadocs and the source. Am I doing something wrong?
推荐答案
with
是Scala中的关键字,例如,用于混合多个特征.
with
is a keyword in Scala, for example, used in mixin multiple traits.
class A extends B with C with D
因此,如果在Java库中将一个方法命名为with
,则在调用该方法时需要用``(反引号)将其括起来:
So if a method is named with
in Java library, you need surround it with `` (backtick) when you calling it:
BinaryAttachment.`with`("cat.png", stream)
这篇关于从Scala访问公共静态Java方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!