Skip to content
Advertisement

Tag: lambda

Java access bean methods with LambdaMetafactory

my question is strongly related to Explicit use of LambdaMetafactory in that thread, some very good examples are provided to use the LambdaMetafactory to access a static method of a class; however, I wonder what is the equivalent code to access a non static field of an existing bean instance. It seems really hard to find an example and every

Java 8 stream map on entry set

I’m trying to perform a map operation on each entry in a Map object. I need to take a prefix off the key and convert the value from one type to another. My code is taking configuration entries from a Map<String, String> and converting to a Map<String, AttributeType> (AttributeType is just a class holding some information. Further explanation is not

Are lambdas garbage collected?

If I’m not mistaken, under certain situations a lambda in Java is generated as an anonymous class instance. For example, in this code the lambda needs to capture a variable from the outside: Does it means that the garbage collector will claim the lambda as an object? Answer No it won’t; this is not how lambdas work. Yes, a class

Possibility to explicit remove Serialization support for a lambda

As already known it’s easy to add Serialization support to a lambda expression when the target interface does not already inherit Serializable, just like (TargetInterface&Serializable)()->{/*code*/}. What I ask for, is a way to do the opposite, explicitly remove Serialization support when the target interface does inherit Serializable. Since you can’t remove an interface from a type a language-based solution would

Iterate an Enumeration in Java 8

Is it possible to iterate an Enumeration by using Lambda Expression? What will be the Lambda representation of the following code snippet: I didn’t find any stream within it. Answer In case you don’t like the fact that Collections.list(Enumeration) copies the entire contents into a (temporary) list before the iteration starts, you can help yourself out with a simple utility

Java8 Lambdas vs Anonymous classes

Since Java8 has been recently released and its brand new lambda expressions looks to be really cool, I was wondering if this means the demise of the Anonymous classes that we were so used to. I’ve been researching a bit about this and found some cool examples about how Lambda expressions will systematically replace those classes, such the Collection’s sort

How do I use the new computeIfAbsent function?

I very much want to use Map.computeIfAbsent but it has been too long since lambdas in undergrad. Almost directly from the docs: it gives an example of the old way to do things: And the new way: But in their example, I think I’m not quite “getting it.” How would I transform the code to use the new lambda way

Advertisement