Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I store a reference to a set of static Java methods from Scala?
    text
    copied!<p>In the context of Eclipse Databinding, there are quite a few Java classes that act as factories for <code>IObservable</code> objects. For instance, there's <code>BeanObservables</code>, <code>PojoObservables</code>, <code>EMFObservables</code>, etc., and they all implement a set of methods similar to</p> <pre><code> public static IObservableValue observeValue(Object target, String property) </code></pre> <p>Now if we were in the Scala world, each of those factories would probably be a singleton object implementing a common trait, say, <code>IObservableFactory</code>, and I could, for instance, pass them around as implicit values to methods that would use them to create data bindings.</p> <p>But as they are defined in Java, it seems I can do none of that. I can't write</p> <pre><code>val pojoObservableFact = PojoObservables </code></pre> <p>because <code>PojoObservables</code> is not recognized as being a value.</p> <p>Is there any way to make the compiler "instantiate" a singleton that would correspond to the <code>PojoObservables</code> class in Scala? Or any workaround for it? I know I could write the singleton myself and forward all method calls, but this sounds a bit tedious.</p> <hr> <p><strong>Edit</strong></p> <p>To make it clearer: this is what I'm trying to do: define a method that creates the observable value using a passed factory.</p> <pre><code>def createObservable(fact: ObservableFactory, target: AnyRef, property: String) = fact.observeValue(target, property) </code></pre> <p>but I wouldn't know how to define <code>ObservableFactory</code> or how to actually pass <code>PojoObservables</code>, a Java class with only static methods, to this <code>createObservable</code> method. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload