Replying to myself, but with the solution. After some discussion on a Scala list, I was able to get the below Scala code to compile. There were two important changes.
1) Using StringBinIndex.named(name) to build the index rather than StringBinIndex.Name(name), due to the interop issues. 2) Parameterising the getIndex function explicitly. Someone on the scala list suggested that this was because the type signature of the Java client code is not strictly correct. I will present their comments here in case someone can confirm? Instead of: public <V extends RiakIndex, T extends RiakIndex.Name<V>> V getIndex(T name) It should be: public <V extends RiakIndex<?>, T extends RiakIndex.Name<V>> V getIndex(T name) The complete Scala example for writing to a key with 2i indexing is as follows: (assumes "riak" is an already connected riak instance) def storeByKeyRaw(bucketName: String, key: String, data: Array[Byte], indexes: Map[String,String] = Map()) = { val bucket = new Namespace("default", bucketName) val loc = new Location(bucket, key) val obj = new RiakObject obj.setValue(BinaryValue.create(data)) indexes.foreach{ case (name, contents) => val idx = StringBinIndex.named(name) obj.getIndexes().getIndex[StringBinIndex,StringBinIndex.Name](idx).add(contents) } val response = riak.execute(new StoreValue.Builder(obj).withLocation(loc).build) // ...... } On Wed, 16 Dec 2015 at 15:10 Toby Corkindale <t...@dryft.net> wrote: > Hi, > I'm having a lot of trouble getting a particular part of the Riak java > client to work when called from Scala. > > There's a Java class which I'm not allowed to instantiate directly, but > must instead call an embedded subclass's static constructor method. > > ie. > import com.basho.riak.client.core.query.indexes.StringBinIndex > val idx = new StringBinIndex.Name("colours") > > However, in Scala, I get this error reported: > Constructor Name in class Name cannot be accessed in class [myclass] > > Docs for the class: > > http://basho.github.io/riak-java-client/2.0.1/index.html?com/basho/riak/client/core/query/indexes/StringBinIndex.html > > I don't suppose anyone can see what I'm doing wrong, or suggest how to > make this work from Scala? > > Cheers, > Toby > >
_______________________________________________ riak-users mailing list riak-users@lists.basho.com http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com