I'm creating some case classes in Scala that I use to persist data mongodb. The client app is written in Java and using my repository by passing in instances of these case classes.
It works fine, unless I use optional fields:
case class Person (name: String, email: Option[String])
Now from Java I don't want to reference Scala's Option, so I'd prefer to override a constructor that allows the client to call something like
new Person("Jack", "[email protected]");
A factory method on the companion object would also be OK. I'm looking for a solution that allows me to write Java without any scala deps, preferably no more convoluted than calling a constructor. Thoughts?
Why is this insufficient?
Surely, it still uses
Option[String]
, but it remains invisible to the client. The only problem is that the Java client code will still see both constructors.