Browsed by
Tag: Lambdas

Method References in Java 8

Method References in Java 8

Method references is a way to pass a reference to a method, that can be invoked at a later stage, with Lambdas. The criteria to a method reference, as with all Lambda expressions, is that it can be assigned to a functional interface. There are 4 different kinds of method references: Reference to a static method When the reference is a static method in a class, for example String::valueOf in the example below. Note, System.out returns an Object, so System.out::println…

Read More Read More

Lambdas in Java 8

Lambdas in Java 8

Java 8 has been out for a while now, and there are a lot of great posts about all the new features, but I’m preparing an introduction for a team that just started to use Java 8, so I thought I could just as well publish my notes as a blog post. Lambdas are actual “just” another way of creating anonymous inner classes, in the pre Java 8 world, we had to write: JButton jButton = new JButton(); jButton.addActionListener(new ActionListener()…

Read More Read More