aerospike-client-java icon indicating copy to clipboard operation
aerospike-client-java copied to clipboard

Type Erasure in 5.1.11

Open Marcus-Rosti opened this issue 3 years ago • 7 comments

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

Marcus-Rosti avatar Jul 29 '22 01:07 Marcus-Rosti

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?

BrianNichols avatar Jul 29 '22 01:07 BrianNichols

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 = ???
}

Marcus-Rosti avatar Jul 29 '22 20:07 Marcus-Rosti

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

BrianNichols avatar Jul 29 '22 20:07 BrianNichols

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

Marcus-Rosti avatar Jul 29 '22 20:07 Marcus-Rosti

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

BrianNichols avatar Jul 29 '22 21:07 BrianNichols

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

Marcus-Rosti avatar Jul 29 '22 21:07 Marcus-Rosti

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

BrianNichols avatar Jul 29 '22 22:07 BrianNichols