64203

Cannot access a Java static method from Scala

Question:

I'm having an issue with Scala and Java interoperability which Google and SO seem to be unhelpful (I've seen similar questions, but none offered a working solution for my case).

I have created a jar file in Java (hosted <a href="https://dl.dropboxusercontent.com/u/3119946/rowl-fetchers.jar" rel="nofollow">here</a>, if you need it to answer this question) which contains a class with a static method. However, I can't seem to access this static method from Scala. Here's the code:

<pre class="lang-scala prettyprint-override">val graph1 = ... val graph2 = ... val union = DirectedGraph.merge(graph1, graph2)

The method exists, and I can access it with normal Java code. In fact, the following <em>works</em>:

<pre class="lang-java prettyprint-override">DirectedGraph<OWLClass> graph1 = ...; DirectedGraph<OWLClass> graph2 = ...; DirectedGraph<OWLClass> union = DirectedGraph.merge(graph1, graph2);

I've checked that the jar files being used by java and scala are the same. And I also checked to see if the method was indeed there with javap.

Is there an idea out there to understand and possibly solve this problem?

Answer1:

The most likely reason (in my experience) is that the Java compiler treats annotations as optional, so that if one of your dependencies uses an annotation and there is no dependency which contains this annotation, it compiles without problems. However, the Scala compiler considers this an error. You may want look at DirectedGraph source along with its supertypes.

Recommend

  • Connect to ONLINE MySQL database using DSN ODBC
  • Integrate gzip with GWT
  • Read csv from zip into shiny app without relying on local directories
  • can't get In-App-Purchase hosted content to be actually hosted
  • How to display callstack line numbers when my program is broken in Rust?
  • Merge 2 arrays and combine results of numerical keys
  • JPA CascadeType.REMOVE not working
  • Sum values in array of hash if they have the same value
  • How to merge keras sequential models with same input?
  • hibernate sets dirty flag (and issues update) even though client did not change value
  • How can Delete be both a DDL and a DML statement
  • converting text file into xml using php?
  • Content-Length header not returned from Pylons response
  • Ajax Loaded meta Tags
  • Xamarin Forms - UWP Fonts
  • sending/ receiving email in Java
  • Trying to switch camera back to front but getting exception
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Jquery - Jquery Wysiwyg return html as a string
  • Apache 2.4 - remove | delete | uninstall
  • Arrays break string types in Julia
  • How to delete a row from a dynamic generate table using jquery?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • WPF Applying a trigger on binding failure
  • Proper way to use connect-multiparty with express.js?
  • Benchmarking RAM performance - UWP and C#
  • Acquiring multiple attributes from .xml file in c#
  • Free memory of cv::Mat loaded using FileStorage API
  • Angular 2 constructor injection vs direct access
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Java static initializers and reflection
  • How can I remove ASP.NET Designer.cs files?
  • unknown Exception android
  • Is there any way to bind data to data.frame by some index?
  • Checking variable from a different class in C#
  • Programmatically clearing map cache
  • Observable and ngFor in Angular 2
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal