Hello,
Maybe the Scala experts here can help me. I'm trying to implement a Function1 in Java, such as:
Function1<Path, Object> fileFilter = new Function1<Path, Object>() { @Override public Object apply(Path v1) { return true; } @Override public <A> Function1<A, Object> compose(Function1<A, Path> g) { return Function1$class.compose(this, g); } @Override public <A> Function1<Path, A> andThen(Function1<Object, A> g) { return Function1$class.andThen(this, g); } };But apparently my implementation of compose andandThenare wrong, and I couldn't understand how I should implement it. It complains that the anonymous function:is not abstract and does not override abstract method <A>andThen$mcVJ$sp(scala.Function1<scala.runtime.BoxedUnit,A>) in scala.Function1
I've also tried to implement AbstractFunction1 so that I don't have to deal with compose and andThen but then I bumped into some issues about serialization, therefore I'm trying to do it via Function1)
Any ideas about how I can implement the compose and andThen methods in Java?
--
Emre
Resp. what is wrong with serialization? Are you sure you need it at all?
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
>
>
>
>
> Hello,
> Thanks for the answer. I managed to get it working by moving my
implementation of scala.AbstractFunction1 to another .java file, making it
implement Serializable and then calling it. (I think it was related to some
mechanisms of Apache Spark). In other words, problem solved.--
> Emre
>
Hello Emre,
Could you explain how you managed to do this because I'm also trying to
implement a serializable version of a scala.Function1 in Java in order to
distribute my Spark computation. I tried to pu the abstractFunction1
implementation in another java file which i made serializable but no change
in the results...
Thanks a lot !
François
public abstract class SerializableFunction1<T1,R> extends AbstractFunction1<T1, R> implements Serializable {
}
new SerializableFunction1<Integer, Integer>(){
public Integer apply(Integer in){
return in + 1;
}
}