Using the Scala Datastax Cassandra Driver

I wanted to learn how to use the scala Datastax Cassandra CQL3 driver, but I think I might have fallen at the first hurdle.

In methods for creating a cluster object in Javadoc, there is an overloaded method for addContactPoints that accepts either a String sequence or a java.net.InetAddress sequence as parameters. Is there a way to simulate this in the idiomatic scala style, so I can try and match the pattern by the type and arity of the 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 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 ? 
+4
source share
1 answer

How to explicitly indicate the type of function?

 import com.datastax.driver.core.Cluster def cp = Cluster.builder().addContactPoint _ def cps(addresses: [String]) : Cluster.Builder = Cluster.builder().addContactPoints(addresses) 
+4
source

Source: https://habr.com/ru/post/1488297/


All Articles