Can We Wean Scala Off Implicit Conversions?

I would imagine that a codebase like ScalaFX would have some problems if implicit conversions were removed. One of its selling points is “Seamless JavaFX/ScalaFX Interoperability”, and as far as I understand that seamless interoperability is provided by implicit conversions.

It essentially wraps Java objects in Scala objects, with implicit conversions between them, e.g.:

object Node {
  implicit def sfxNode2jfx(v: Node): jfxs.Node = if (v != null) v.delegate else null
}

One could of course fall back to using explicit methods e.g .toJfx, and .toSfx (as extension method, or alternatively SFX.fromJfx), but implicit conversions remove this “noise”.

In general I think allowing methods inside a class’ companion object for implicitly converting to/from that class is very useful, whether it is done with the current implicit def mechanism or something else.

1 Like