Note that the cancel
only attempts to cancel the task, there are no guarantees according to the Javadoc. So you don't really have to implement it to do something -- depending on what the future computation is, ignoring the cancel
call may not be subsequential for the entire application.
If you really need to cancel it, see this question for a half-solution.
Otherwise, you could use your second solution -- with the help of some implicit conversions you could make it look nicer.
object JavaInterOp {
implicit def f2future[F[_]](f: () => T): java.util.concurrent.Future[T] = fc(f)
}
This way, the import controls which conversion you want to provide and when.
One issue with this is that it might do the conversion where you don't really want it -- it might yield surprising effects.