Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing public static java method from scala

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?

like image 384
Dax Fohl Avatar asked Feb 05 '13 23:02

Dax Fohl


1 Answers

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)
like image 138
Brian Hsu Avatar answered Oct 29 '22 08:10

Brian Hsu