user462455
user462455

Reputation: 13618

Using Java Generics in Scala

When integrating a java library with Scala codebase, running into following error when uisng one of Generic objects from Java into Scala.

val MyObject<SomeOtherclass>  = MyObject.factoryMethod()

Above code gives a compilation error because it is not a valid scala statement.

How can we use Java generic objects in scala codebase.

Upvotes: 0

Views: 93

Answers (1)

user unknown
user unknown

Reputation: 36259

val myObject: MyObject[T] = MyObject.factoryMethod ()

would be Scala-Syntax. Note that objects are usually written in lower case. The type inference might solve the issue without giving the type explicitly, but it might be a good idea for documentation reasons to specify it though, and to get an early error, if your reasoning was wrong.

Upvotes: 1

Related Questions