4

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 ?

1 Answer 1

4

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Nearly there - I ended up with def cps(addresses: Seq[String]): Cluster.Builder = Cluster.builder().addContactPoints(addresses:_*)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.