Skip to content

Scala improvements#591

Merged
alexmoore merged 3 commits intodevelopfrom
scala-improvements
Feb 1, 2016
Merged

Scala improvements#591
alexmoore merged 3 commits intodevelopfrom
scala-improvements

Conversation

@alexmoore
Copy link
Contributor

This fixes issue #585 & #584.

TLDR; This replaces some RiakIndex raw type declarations with Scala friendly RiakIndex<?> unbounded wildcard type declarations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this basically says that RiakIndex will be a generic type without any type constraints?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it says that the type parameter used by RiakIndex will be of some specific (but unknown) type - but for our purposes we (and the compiler) don't need to know. We don't use the type parameter wrapped by RiakIndex anywhere in the Name class, so we could use either.

On the flip side I don't see how you could ever use the raw type by itself (RiakIndex, no type parameter), since RiakIndex is an abstract class.

@lukebakken
Copy link
Contributor

@TJC - you should be interested in these changes 😄

@lukebakken
Copy link
Contributor

These changes look good to me ... not that I know 100% what they do 😄

👍

@alexmoore
Copy link
Contributor Author

@TJC - Do you have any Scala code that I could test these changes against, or that show the trouble you were having with the raw types?

@TJC
Copy link

TJC commented Feb 1, 2016

Create demo.scala:

package foo

import com.basho.riak.client.core.query.RiakObject
import com.basho.riak.client.core.util.BinaryValue
import com.basho.riak.client.core.query.indexes.StringBinIndex

class RiakTest {

  val obj = new RiakObject
  obj.setValue(BinaryValue.create("hello world"))
  obj.setContentType("application/json")

  val idxtype = StringBinIndex.named("myindex")
  val indexes = obj.getIndexes
  indexes.getIndex(idxtype).add("myvalue")

}

Try to compile it with:
scalac -classpath riak-client-2.0.3.jar:netty-all-4.0.33.Final.jar demo.scala

@TJC
Copy link

TJC commented Feb 1, 2016

I can make a version that uses sbt to get the dependencies and so forth, but I figured that the smallest, simplest demo was best. It doesn't actually do anything when compiled, but the compilation failure is the test.

@alexmoore
Copy link
Contributor Author

@TJC Thanks!

So good news and bad news.

Good news:
You can get it to work by being explicit with the types on getIndex():
indexes.getIndex[StringBinIndex,StringBinIndex.Name](idxtype).add("myvalue")

Bad news:
No matter how much cleanup I do to the type system between RiakIndex, RiakIndex.Name, and RiakIndexes.[get|has|remove]index(), I cannot get Scala to infer the types correctly.

I even tried being more explicit and giving Name an extra type parameter to hint at what it's main type parameter that extends RiakIndex is : `>-><V, U extends RiakIndex>`

But Scala just laughed and said it couldn't match another type parameter.

I'll keep the <?> additions I made becuase they are more correct even if Java don't care, and then we'll have to make a note for Scala users to be explicit about the types for getIndex(). 😭

alexmoore added a commit that referenced this pull request Feb 1, 2016
Documentation improvements, fixing a few type declarations around indexes.
@alexmoore alexmoore merged commit 3d7f7ac into develop Feb 1, 2016
@alexmoore alexmoore deleted the scala-improvements branch February 1, 2016 19:46
@TJC
Copy link

TJC commented Feb 2, 2016

Thanks for trying!

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

Successfully merging this pull request may close these issues.

3 participants