Blankman
Blankman

Reputation: 267280

How to write this java builder with generics to scala?

I'm trying to write this java code in scala, but I am getting a compile error.

Document<String, String> doc = Document.<String, String>builder().id("newDocId").score(1d).build();

I am trying:

val doc = Document.<String, String>builder().id("newDocId").score(1d).build();

How do I convert this java generic usage?

I also tried Document[String, String] but I get an error sayingDocument is not a value.

Upvotes: 0

Views: 132

Answers (1)

user
user

Reputation: 7604

Try this:

val doc = Document.builder[String, String]().id("newDocId").score(1d).build()

Scala uses square brackets for generics (and semicolons are optional). Also, the type parameters go to the method, not the object.

Upvotes: 4

Related Questions