0

I have to convert this code from Java to Scala:

 Connection connection = DriverManager.getConnection("jdbc: ...");
 OlapConnection olapConnection = connection.unwrap(OlapConnection.class);

Problem is to convert the unwrap parameter. This is my attempt in Scala:

val connection = DriverManager.getConnection("jdbc: ...")
val olapConnection = connection.unwrap(OlapConnection.getClass)

I get the error in OlapConnection.getClass :

value getClass is not a member of object org.olap4j.OlapConnection Note that OlapConnection extends Any, not AnyRef. Such types can participate in value classes, but instances cannot appear in singleton types or in reference comparisons.

What is the equivalent of the unwrap parameter in Scala?

Xavier Guihot
  • 54,987
  • 21
  • 291
  • 190
ps0604
  • 1,227
  • 23
  • 133
  • 330

1 Answers1

2

The equivalent of Java's T.class in Scala would be classOf[T]:

val connection = DriverManager.getConnection("jdbc: ...")
val olapConnection = connection.unwrap(classOf[OlapConnection])

Note: not tested as I'm not sure what are your dependencies.

Xavier Guihot
  • 54,987
  • 21
  • 291
  • 190
  • 1
    More details in [this answer to "Scala equivalent of Java java.lang.Class Object"](https://stackoverflow.com/a/1135317/2707792). – Andrey Tyukin Mar 30 '18 at 18:12