Tweaking some interfaces to better support Java 8 Lambdas

1 view
Skip to first unread message

Justin Basilico

unread,
Apr 3, 2014, 12:39:50 AM4/3/14
to cognitiv...@googlegroups.com
Hey all,

I'm excited about the Lambda support in Java 8, which makes it very easy to implement simple, single-function interfaces by defining functions inline. I thought this could work very well with certain interfaces in the Foundry like Kernel, Metric, DivergenceFunction, PerformanceEvaluator, etc. to let you do things like: 

KMeansFactory.create(4, (Vector x, Vector y) -> x.minus(y).normInfinity(), new Random());

However, several of these interfaces currently extend CloneableSerializable, which means that they technically have more than one method that needs to be implemented (a public clone), so the current lambda support doesn't work for them (without building adapter classes).

Thus, my proposal is to drop the "extends CloneableSerializable" from many of these simple functional style interfaces. Of course, implementations of these that need to be serialized can be by extending AbstractCloneableSerializable, as is normally done. Lambdas by default can be serialized, though it is not suggested.

The main impact of this change several clone methods need to be tweaked to call cloneSmart rather than cloneSafe. This isn't a full switch to Java 8, just something to make it easier to use the Foundry when you are doing so in an application using Java 8.

Are there any objections to this?

Thanks, : )
Justin



brandon willard

unread,
Apr 3, 2014, 12:48:52 AM4/3/14
to cognitiv...@googlegroups.com
I second this motion.


--
You received this message because you are subscribed to the Google Groups "Cognitive Foundry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cognitive-foun...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephen Mallette

unread,
Apr 3, 2014, 7:05:29 AM4/3/14
to cognitiv...@googlegroups.com
Sounds like a very sensible change to make.

Stephen
Reply all
Reply to author
Forward
0 new messages