#218

Type Erasure in 5.1.11

OpenMarcus-Rostiopened 4y ago

I get this error when implementing a dummy class in scala:

[error] override def get(eventLoop: com.aerospike.client.async.EventLoop, listener: com.aerospike.client.listener.RecordArrayListener, policy: com.aerospike.client.policy.BatchPolicy, keys: Array[com.aerospike.client.Key], binNames: String*): Unit at line 233 and
[error] override def get(eventLoop: com.aerospike.client.async.EventLoop, listener: com.aerospike.client.listener.RecordArrayListener, policy: com.aerospike.client.policy.BatchPolicy, keys: Array[com.aerospike.client.Key], operations: com.aerospike.client.Operation*): Unit at line 252
[error] have same type after erasure: (eventLoop: com.aerospike.client.async.EventLoop, listener: com.aerospike.client.listener.RecordArrayListener, policy: com.aerospike.client.policy.BatchPolicy, keys: Array[com.aerospike.client.Key], binNames: Seq): Unit

Activity

7
BrianNichols4y ago

Scala seems to be reducing different variable args ("String... binNames" and "Operation... ops") to the same scala "Seq" type. This causes methods to be considered duplicates of each other. I'm not sure this can be fixed on the java client side.

Can you provide scala source code that reproduces this error?

Marcus-Rosti4y ago

it was pretty simple to recreate, just try implementing the class in scala

class MySpike extends IAerospikeClient {
... other methods
  def get(eventLoop: com.aerospike.client.async.EventLoop, listener: com.aerospike.client.listener.RecordArrayListener, policy: com.aerospike.client.policy.BatchPolicy, keys: Array[com.aerospike.client.Key], binNames: String*): Unit = ???
  def get(eventLoop: com.aerospike.client.async.EventLoop, listener: com.aerospike.client.listener.RecordArrayListener, policy: com.aerospike.client.policy.BatchPolicy, keys: Array[com.aerospike.client.Key], operations: com.aerospike.client.Operation*): Unit = ???
}
BrianNichols4y ago

IAerospikeClient is an interface and MySpike is a class. Shouldn't you be extending AerospikeClient?

Marcus-Rosti4y ago

right, you'd extend or implement an interface, not the class itself

BrianNichols4y ago

To implement client methods: class MySpike implements IAerospikeClient To extend client: class MySpike extends AerospikeClient

Marcus-Rosti4y ago

right, I want to implement a subset of the methods to simulate in unit tests

BrianNichols4y ago

Scala does not directly support implementing java interfaces with method signatures that only differ by variable args. There is a workaround that is described here:

https://stackoverflow.com/questions/24132089/how-to-implement-java-interface-in-scala-with-multiple-variable-parameter-method