Accessing non-final local variables from a lambda expression
Reinier Zwitserloot
reinier at zwitserloot.com
Sun Feb 28 12:17:13 PST 2010
Replies inline.
On Sun, Feb 28, 2010 at 8:44 PM, Peter Levart <peter.levart at gmail.com>wrote:
> With "frame object" I meant an object, allocated on the heap whose class
> is constructed by compiler and holds all captured local variables (whether
> final or non-final). I don't know why but this terminology is used by Neal
> and others.
>
> With MethodHandles, local vars can be captured one-by-one via
> (MethodHandles.insertArgument) but it might still be better to construct a
> single "frame object" to hold all of them when their number reaches a
> certain limit or when at least one of them is non-final.
>
So, there's a marginal speed benefit that grows with the number of
(effectively) non-final local variables captured, where with capturing 1,
the speed benefit is zero?
I doubt this is going to be worth the effort to implement. Would it even be
faster in the first place? any modification of a shared variable still needs
to visit the heap to grab the shared object. Presumably if there are 3
variables all on the heap they'd be part of the same generation and most
likely in the same block, which suggests that the odds of a cache miss after
the first access is low either way.
It is the idea of JSR308 (Type annotations) that you can attach an
> annotation to any type. These annotations are treated by compiler as
> additional properties of the type (if types are nouns, type annotations are
> adjectives).
>
I don't agree with this notion, but, nevertheless, it remains a standing
rule: Annotations cannot change what code does, it can at best change the
number and nature of warnings emitted by the compiler. Unless the powers
that be want to consider nixing this rule, I don't see how this approach is
going to pass muster.
> @S public interface SortedSet<E> {
>
> ...
>
> @S Comparator<? super E> comparator();
>
> @S acts as a sort of aditional SortedSet's generic parameter. A @Safe
> SortedSet is then an instance of a SortedSet that contains a @Safe
> Comparator.
>
Huh? By annotating the interface, I would say the intent is that *ALL*
SortedSets are safe. Which isn't necessarily the case, of course.
More information about the lambda-dev
mailing list