Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Erasure in 5.1.11 #218

Open
Marcus-Rosti opened this issue Jul 29, 2022 · 7 comments
Open

Type Erasure in 5.1.11 #218

Marcus-Rosti opened this issue Jul 29, 2022 · 7 comments

Comments

@Marcus-Rosti
Copy link

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
Copy link
Member

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
Copy link
Author

Marcus-Rosti commented Jul 29, 2022

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
Copy link
Member

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

@Marcus-Rosti
Copy link
Author

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

@BrianNichols
Copy link
Member

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

@Marcus-Rosti
Copy link
Author

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

@BrianNichols
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants