1

I'm trying to do something like this in scala:

class SessionObject {
 def setParameter(parameterOne : String): Unit = {
 //Doing some stuff
 }
 def getResult(javaListParameter: java.util.List[String]): JsonObject = {
 //doing some stuff
 }
}

Once I compile the scala code I'm trying to use it in Java as a library. Something like this:

SessionObject object = new SessionObject();
object.setParameter("Something");
List<String> theList = new ArrayList<String>();
object.getResult(theList);

However, I'm not able to see/access the "getResult" method in Java. Is this a scala limitation or I'm missing something?

Thanks!

EDIT:

I tried this solution, however doesn't seem to work. Any method that uses java.util.List as a parameter or as a result cannot be used in java code.

Forgot to mention the compiler info. I'm using the maven-scala-plugin version 2.15.2 with scala version 2.10.3

EDIT:

Ok, as wingedsubmariner suggested, I ignored the IDE pre-compiling hints and compiled anyway. Now I'm getting this:

method com.*.*.*.*.SessionObject.getResult(java.lang.String,scala.collection.immutable.List<java.lang.String>,java.lang.String,scala.collection.immutable.List<java.lang.String>) is not applicable
      (actual argument java.util.List<java.lang.String> cannot be converted to scala.collection.immutable.List<java.lang.String> by method invocation conversion)
    method com.*.*.*.*.SessionObject.getResult(java.lang.String,java.util.ArrayList<java.lang.String>,java.lang.String,java.util.ArrayList<java.lang.String>) is not applicable
      (actual argument java.util.List<java.lang.String> cannot be converted to java.util.ArrayList<java.lang.String> by method invocation conversion)

This seems to tell me that somehow the java.util.List parameter definition is being ignored.

Community
  • 1
  • 1
ra2085
  • 814
  • 4
  • 13
  • 1
    What error are you getting? What do you mean by 'I'm not able to see/access the "getResult" method in Java'? – wingedsubmariner Apr 24 '14 at 21:49
  • no error, it's simply not an accesible/usable method, meaning I can use 'setParameter("something")' but I can't use getResult (not found method/symbol). It's like trying to use a method that hasn't been defined. Thanks for the interest. – ra2085 Apr 24 '14 at 22:03
  • 1
    Is the not found error produced by your IDE or the Java compiler? – wingedsubmariner Apr 24 '14 at 22:03
  • IDE. Netbeans 8.0 using scala plugin. – ra2085 Apr 24 '14 at 22:05
  • 1
    Try writing the code anyway and see if the Java compiler accepts it. This will let us narrow down if it is an IDE issue or something else. – wingedsubmariner Apr 24 '14 at 22:06
  • getting weird results, let me just make sure maven is installing the last compiled scala code properly. – ra2085 Apr 24 '14 at 22:10
  • Just updated. I'll remove completely the solution I found on the first edit, hopefully I'll get something different. – ra2085 Apr 24 '14 at 22:19
  • Yup. It seems it was an IDE issue. It's weird though, because I tried plenty of objects from the java libraries and all worked as expected on the IDE (no warnings or code hints), just the collections package seems to have an issue. – ra2085 Apr 24 '14 at 22:25
  • That is weird. It might be worthwhile filing a bug with the Netbeans Scala plugin developers. – wingedsubmariner Apr 24 '14 at 22:46

1 Answers1

0

It seems it was a IDE issue. I explored a different approach thanks to wingedsubmariner. I'm using Netbeans 8.0 using the available Scala plugin. When I use Java collections as parameters or return types, the IDE is not recognising those methods, meaning they dont appear on the code hints and they get flagged as if they were not defined. I can compile the code ignoring those code warnings and works as expected.

ra2085
  • 814
  • 4
  • 13