Accessing public static java method from scala

家住魔仙堡 提交于 2019-12-22 06:43:35

问题


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?


回答1:


with is a keyword in Scala, for example, used in mixin multiple traits.

class A extends B with C with D

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)


来源:https://stackoverflow.com/questions/14719229/accessing-public-static-java-method-from-scala

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!