Nice to @Share?
Gernot Neppert
mcnepp02 at googlemail.com
Tue Feb 23 07:21:50 PST 2010
2010/2/23 <David.Moss at ubs.com>:
> i.e.: what would we need to make the following code do what it is meant to:
>
> public class C {
> public #int() getSequenceGenerator(int start, int increment) {
> return #int() {
> int ret = start;
> start += increment;
> return ret;
> };
> }
> }
public interface IntSequence
{
public int next();
}
public class C {
public IntSequence() getSequenceGenerator(final int start, final
int increment) {
return new IntSequence() {
int current = start;
public int next()
{
int ret = current;
current += increment;
return ret;
};
}
}
The point I'm trying to make:
The concept of a "Sequence generator" is obviously inherently
stateful. Every invocation of its parameterless method is meant to
yield a different value. IMHO, this is best modelled by means of a
designated interface, not by a lambda.
More information about the lambda-dev
mailing list