In cases like Spark, functions need to be serialized. So the FromJavaFunction and the likes should have a default constructor and be serializable.