1
[error] both method addVertex in class OrientBaseGraph of type (x$1: Any, x$2: <repeated...>[Object])com.tinkerpop.blueprints.impls.orient.OrientVertex
[error] and  method addVertex in class OrientBaseGraph of type (x$1: Any)com.tinkerpop.blueprints.impls.orient.OrientVertex
[error] match argument types (String)
[error]         val npNode = g.addVertex(f"class:$NPPhrase")
[error]

How do I get Scala to pick the method I am trying to call (the more specific one) ?

Oh and while in this context g.addVertext(...,Nil) is semantically equivalent, I still want to know how to solve the problem above.

Hassan Syed
  • 20,075
  • 11
  • 87
  • 171

1 Answers1

3

The compiler says right things to you.

addVertex(f"class:$NPPhrase") matches both addVertex(Any) and addVertex(x$1: Any, x$2: Any*). This happens because the x$2 parameter may be empty and you can omit it when calling the addVertex(x$1: Any, x$2: Any*) (like addVertex("whatever"))

The options are:

  1. Rename one of the methods.
  2. Change the addVertex(x$1: Any, x$2: Any*) signature to addVertex(x$1: Any, x$2: Any, x$3: Any*), so that it handles only calls with 2 or more parameters. (I assume your addVertex(x$1: Any) and addVertex(x$1: Any, x$2: Any*) behave the same for one parameter)
serejja
  • 22,901
  • 6
  • 64
  • 72
  • 1
    Yep :/ but I don't have access to that code. It's part of OrientDB. Surely Scala has some machinery for this to deal with legacy code ? – Hassan Syed Feb 10 '14 at 14:16
  • 1
    Well, that's a nice observation indeed.. I suppose you're using some kind of Java library for OrientDB. The problem is that Scala treats this as a compilation error for an obvious reason (it cannot choose by itself which method to invoke), but Java just runs the method without varargs and does not even complain. – serejja Feb 10 '14 at 14:30
  • It seems like this is a known issue. Please read this: http://stackoverflow.com/questions/3313929/how-do-i-disambiguate-in-scala-between-methods-with-vararg-and-without – serejja Feb 10 '14 at 14:36