Question

I wanted to explore using the Datastax Cassandra CQL3 driver from scala but think I may have fallen at the first hurdle.

In methods for creating a Cluster object in the Javadoc there is an overloaded method for addContactPoints which take either a sequence of String or a Sequence of java.net.InetAddress as parameters. Is there a way of modelling this in an idiomatic Scala way so I can try and pattern match on the type and arity of an input parameter to call the correct method.

with

import com.datastax.driver.core.Cluster

def cp = Cluster.builder().addContactPoint _

def cps = Cluster.builder().addContactPoints _

cp returns

cp: String => com.datastax.driver.core.Cluster.Builder 

cps however gives

error: ambiguous reference to overloaded definition,

both method addContactPoints in class Builder of type (x$1: <repeated...>[java.net.InetAddress])com.datastax.driver.core.Cluster.Builder

and  method addContactPoints in class Builder of type (x$1: <repeated...>[String])com.datastax.driver.core.Cluster.Builder
match expected type ?
Était-ce utile?

La solution

What about explicitly specifying the type of the function?

import com.datastax.driver.core.Cluster

def cp = Cluster.builder().addContactPoint _
def cps(addresses: [String]) : Cluster.Builder = Cluster.builder().addContactPoints(addresses)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top