In Java 8, it looks like lambdas classes are stored in an array. For example, suppose we have this class:
public class LambdaFactory { public Supplier<Integer> getOne(){ return () -> 42; } public Supplier<Integer> getTwo(){ return () -> 128; } public Supplier<Integer> getThree(){ return () -> 3; } }
and then I print it like this:
System.out.println(factory.getOne()); System.out.println(factory.getOne()); System.out.println(factory.getTwo()); System.out.println(factory.getThree());
the output will be something like
examples.LambdaFactory$$Lambda$1@4e515669 examples.LambdaFactory$$Lambda$1@4e515669 examples.LambdaFactory$$Lambda$2@1b9e1916 examples.LambdaFactory$$Lambda$3@ba8a1dc
So we can see two things here. The same lambda, called twice, gives us the same lambda object (this is not the same as with the internal anon classes, where each time we could get a new one). We also see that they look like they are stored in some kind of Lambda structure, which is part of the class
My question is: can I get lambdas in the class? I have no reason for this, I just love to cut things.
java lambda java-8
ryber
source share