aerospike / aerospike-client-java

Aerospike Java Client Library
Other
236 stars 212 forks source link

Type Erasure in 5.1.11 #218

Open Marcus-Rosti opened 2 years ago

Marcus-Rosti commented 2 years 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
BrianNichols commented 2 years 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-Rosti commented 2 years 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 = ???
}
BrianNichols commented 2 years ago

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

Marcus-Rosti commented 2 years ago

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

BrianNichols commented 2 years ago

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

Marcus-Rosti commented 2 years ago

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

BrianNichols commented 2 years 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