I've just got an issue with the BluePrints API.
I've executed the following Scala commands:
val dbBasename = "C:\\Users\\taatoal1\\tmp\\orientdb\\databases\\"
val dbpath = "test_ingest"
val (uname, pwd) = ("admin", "admin")
val graph = new OrientGraph(s"plocal:$dbpath", uname, pwd)
graph.addVertex("class:Employee")
and I got the following error
<console>:14: error: ambiguous reference to overloaded definition,
both method addVertex in class OrientBaseGraph of type (x$1: Any, x$2: <repeated...>[Object])com.tinkerpop.blueprints.impls.orient.OrientVertex
and method addVertex in class OrientBaseGraph of type (x$1: Any)com.tinkerpop.blueprints.impls.orient.OrientVertex
match argument types (String)
graph.addVertex("class:Employee")
^
Do you have any idea what I did wrong?
Thanks in advance
In the end I found out that there is another version of addVertex that takes two strings as parameters: the class name and the cluster name.
Related
Currently I am facing the following compilation error in Scala against Java 9:
: ambiguous reference to overloaded definition,
both method putAll in class Properties of type (x$1: java.util.Map[_, _])Unit
and method putAll in class Hashtable of type (x$1: java.util.Map[_ <: Object, _ <: Object])Unit
match argument types (java.util.Properties)
newProps.putAll(props)
newProps is defined as:
val newProps = new Properties
I tried variants of newProps.asInstanceOf[java.util.Map[...]] but got different compilation errors.
Any hint is welcome.
As #Ted pointed out this is a known issue. One workardound would be to subsitute putAll with something like this:
props.forEach((k, v) => newProps.put(k, v))
Note that by doing this your operation is not atomic anymore but most probably this is not important in your case.
I have the following code:
case class A[T](a:T, b:Array[Int])
object A {
def apply[T](aa:T):A[T] = A(aa, Array(1, 2, 3))
}
trait TLike[T]
case class TSample1[T](str:String) extends TLike[T]
Why if I instantiate from A with type I get the following error:
object tmp extends App{
val a = A[TLike[TSample1]](TSample1("dumb"))
}
Error:
overloaded method value apply with alternatives:
(a: TLike[TSample1],b: Array[Int])A[TLike[TSample1]] <and>
(aa: TLike[TSample1])A[TLike[TSample1]]
cannot be applied to (TSample1[Nothing])
val a = A[TLike[TSample1]](TSample1("dumb"))
But if I just leave it to Scalac it works correctly:
object tmp extends App{
val a = A(TSample1("dumb"))
}
If we start with your case that compiles, you call object A's apply method, which works as expected.
If we later go to the example that doesn't compile and look at the compile error:
Main.scala:10: error: overloaded method value apply with alternatives:
(a: TLike[TSample1],b: Array[Int])A[TLike[TSample1]] <and>
(aa: TLike[TSample1])A[TLike[TSample1]]
cannot be applied to (TSample1[Nothing])
val a = A[TLike[TSample1]](TSample1("dumb"))
^
one error found
It says that it finds two apply methods, one which you defined and one which is the standard case class method (read more about that if you need to).
I'm guessing you try to call this method:
def apply[T](aa:T):A[T] = A(aa, Array(1, 2, 3))
However you can't call the A object's apply function with a template. The other call doesn't match since it also needs an array. Also the types TLike[TSample1] is not equal to TSample1.
Actually it's hard to understand what you are trying to achieve here, but you should consider two things:
TSample take arguments, so Tlike[TSample] is pretty complex type
as there no hints in parameters in for TSample.apply what type parameter T should be, it would be inferred to Nothing by default
This for example would compile
A[TLike[TSample1[_]]](TSample1[TSample1[_]]("dumb"))
Whis would also:
A[TLike[Nothing]](TSample1("dumb"))
Latter is equivalent for
A(TSample1("dumb"))
without any type specification
i've been getting beat up attempting to match on an overloaded method.
i'm new to scala and specs2, so that is likely one factor ;)
so i have a mock of this SchedulerDriver class
and i'm trying to verify the content of the arguments that are being
passed to the signature of this launchTasks method:
http://mesos.apache.org/api/latest/java/org/apache/mesos/SchedulerDriver.html#launchTasks(java.util.Collection,%20java.util.Collection)
i have tried the answers style like so:
val mockSchedulerDriver = mock[SchedulerDriver]
mockSchedulerDriver.launchTasks(haveInterface[Collection[OfferID]], haveInterface[Collection[TaskInfo]]) answers { i => System.out.println(s"i=$i") }
and get
ambiguous reference to overloaded definition, both method launchTasks in trait SchedulerDriver of type (x$1: org.apache.mesos.Protos.OfferID, x$2: java.util.Collection[org.apache.mesos.Protos.TaskInfo])org.apache.mesos.Protos.Status and method launchTasks in trait SchedulerDriver of type (x$1: java.util.Collection[org.apache.mesos.Protos.OfferID], x$2: java.util.Collection[org.apache.mesos.Protos.TaskInfo])org.apache.mesos.Protos.Status match argument types (org.specs2.matcher.Matcher[Any],org.specs2.matcher.Matcher[Any])
and i have tried the capture style like so:
val mockSchedulerDriver = mock[SchedulerDriver]
val offerIdCollectionCaptor = capture[Collection[OfferID]]
val taskInfoCollectionCaptor = capture[Collection[TaskInfo]]
there was one(mockSchedulerDriver).launchTasks(offerIdCollectionCaptor, taskInfoCollectionCaptor)
and get:
overloaded method value launchTasks with alternatives: (x$1: org.apache.mesos.Protos.OfferID,x$2: java.util.Collection[org.apache.mesos.Protos.TaskInfo])org.apache.mesos.Protos.Status <and> (x$1: java.util.Collection[org.apache.mesos.Protos.OfferID],x$2: java.util.Collection[org.apache.mesos.Protos.TaskInfo])org.apache.mesos.Protos.Status cannot be applied to (org.specs2.mock.mockito.ArgumentCapture[java.util.Collection[mesosphere.mesos.protos.OfferID]], org.specs2.mock.mockito.ArgumentCapture[java.util.Collection[org.apache.mesos.Protos.TaskInfo]])
any guidance or suggestions on how to approach this appreciated...!
best,
tony.
You can use the any matcher in that case:
val mockSchedulerDriver = mock[SchedulerDriver]
mockSchedulerDriver.launchTasks(
any[Collection[OfferID]],
any[Collection[TaskInfo]]) answers { i => System.out.println(s"i=$i")
The difference is that any[T] is a Matcher[T] and the overloading resolution works in that case (whereas haveInterface is a Matcher[AnyRef] so it can't direct the overloading resolution).
I don't understand why the first alternative didn't work, but the second alternative isn't working because scala doesn't consider implicit functions when resolving which overloaded method to call, and the magic that lets you use a capture as though it were the thing you captured depends on an implicit function call.
So what if you make it explicit?
val mockSchedulerDriver = mock[SchedulerDriver]
val offerIdCollectionCaptor = capture[Collection[OfferID]]
val taskInfoCollectionCaptor = capture[Collection[TaskInfo]]
there was one(mockSchedulerDriver).launchTasks(
offerIdCollectionCaptor.capture, taskInfoCollectionCaptor.capture)
Here is my code
class AuthAction(callbackUri:String) extends ActionBuilder[UserRequest] with ActionRefiner[Request,UserRequest]{
override def refine[A](request: Request[A]): Future[Either[Result,UserRequest[A]]] = {
val redirectUri = routes.Application.callback(None, None).absoluteURL(request)
getUser(request) match {
case Some(user) => Future.successful(Right(new UserRequest(user,request)))
case _ => Future.successful(Left(oauthLogin(callbackUri,redirectUri)(request)))
}
}
}
When i try to compile this code, i get the following error
[error] (secure: Boolean)(implicit request: play.api.mvc.RequestHeader)String <and>
[error] (x$1: play.mvc.Http.Request)String
[error] cannot be applied to (play.api.mvc.Request[A])
[error] val redirectUri = routes.Application.callback(None, None).absoluteURL(request)
is this something to do with implicit params? whats happening here?
It wants play.mvc.Http.Request, and you are trying to pass in play.api.mvc.Request. They are not compatible.
Edit: To answer the question you are asking in the comment ...
Well, I am not sure which parameter you are talking about. There are two flavors of this function:
The one, that it seems like you are trying to call -
absoluteURL(request: play.mvc.Http.Request) - does not take any implicit params, it just needs the request of the right type.
The other one - absoluteURL(secure: Boolean)(implicit request: play.api.mvc.RequestHeader) - does have an implicit parameter, which is also of a different type from what you have (RequestHeader, not Request).
If you declare a variable holding this requestHeader as implicit, and it is in scope, you can call the latter function without specifying it explicitly:
implicit val requestHeader = createMyRequestHeader()
routes.Application.callback(None, None).absoluteURL(true)
or you can still pass it in explicitly like you would do with a regular parameter (in this case you don't need it to be declared as implicit):
routes.Application.callback(None, None).absoluteURL(true)(requestHeader)
I'm trying to load a bunch of com.mongodb.DBObject objects in to a Vaadin BeanItemContainer to display in a table. I'm getting stuck on the translation of the constructor from Java to Scala.
The constructor definition is:
BeanItemContainer(Class<? extends BT> type)
This passes the scala compiler:
val bic = new BeanItemContainer(Class.forName("com.mongodb.DBObject"))
However, when I try to add an item:
mtl.toArray.foreach {t => bic.addBean(t)}
I get the following error:
[ERROR]com/sentientswarm/traderdashboard/UploadTradesWindow.scala:140: error: type mismatch;
found : t.type (with underlying type com.mongodb.DBObject)
required: ?0 where type ?0
mtl.toArray.foreach {t => bic.addBean(t)}
Any thoughts/suggestions?
UPDATE:
Tried:
val bic: BeanItemContainer[DBObject] = new BeanItemContainer(Class.forName("com.mongodb.DBObject"))
Result:
[ERROR]com/sentientswarm/traderdashboard/UploadTradesWindow.scala:140: error: type mismatch;
found : java.lang.Class[?0(in value bic)] where type ?0(in value bic)
required: java.lang.Class[_ <: com.mongodb.DBObject]
val bic: BeanItemContainer[DBObject] = new BeanItemContainer(Class.forName("com.mongodb.DBObject"))
^
Thanks,
John
Any reason you're using Class.forName? I don't think the compiler can infer the type from the returned object from that call, it would just be Class[_]. If you use classOf, it should let the compiler determine the type:
val bic = new BeanItemContainer[DBObject](classOf[DBObject]))
In other words: DBObject.class in Java translates to classOf[DBObject] in Scala.
Try this:
val bic: BeanItemContainer[BT] = new BeanItemContainer(Class.forName("com.mongodb.DBObject"))
By the way, you removed the "^" marker of where in the line the error is. Please, keep it when pasting error messages.