Scala: the implementation of the Java interface results in an incompatible type

advertisements

i have a Java-Interface that i want to implement in Scala. The Interface contains the following method-declaration:

  public Boolean existsTable(String tableId);

My Scala-Implementation is:

  override def existsTable(tableId: String): Boolean = {
    val dbmeta = connection.getMetaData()
    val dbtables = dbmeta.getTables(null, null, channelId, null)
    if (dbtables.next())
      // table exists
      return true
    else
      return false
  }

For some reason i get the error "overriding method existsTable in trait xyz of type (tableId: String)Boolean; method existsTable has incompatible type"

But i dont really know where there could be an incompatible type since its just a Boolean that is the return-type?

Greetings.

PS: I had this method working once before in the exact way, when i wasnt implementing an interface, so there should be no error in the method itself. It's just the Implementation of the Java-Interface in Scala that's giving me a hard time.


The reason why this is not working, as indicated in the comments is that Scala's Boolean is not the same as Java's Boolean. A quick way to fix this is:

import java.lang.{Boolean => JBoolean}

override def existsTable(tableId: String): JBoolean

By aliasing the type, it's a little more clear what you meant to return. You could of course just define it as:

override def existsTable(tableId: String): java.lang.Boolean