Reputation: 13618
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
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