As a bit of background, I'm using joda DateTime from Scala. It seems that everywhere a Scala developer uses Joda DateTime, they define some implicit datetimeOrdering
, which they then import. Each library seems to define its own. Occasionally there are conflicts from having multiple definitions from different libraries in scope.
I'm curious if and how the Java library (in this case joda, but it's just an example) might define such an implicit in its Java source code, such that it would compile to equivalent scala bytecode, so that it could be imported in a scala program. I know I can do things like implement def +(x:Whatever):Whatever
in Java using $plus(...)
, but I don't know how I would define an implicit.
I'm not a joda developer, just curious how this would work. Obviously joda could include a single scala file in their project, but I'm curious if other options exist. Does defining an implicit in Java require the scala-tools.jar being on the classpath? Can an implicit be defined directly in Java code? What does the implementation of implicit
actually look like?