This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
button.addActionListener(e -> { ui.dazzle(e.getModifiers()); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> names = Arrays.asList("Alice", "Bob", "Charlie", "Dave"); | |
List<String> filteredNames = names | |
.filter(e -> e.length() >= 4) | |
.into(new ArrayList<String>()); | |
for (String name : filteredNames) { | |
System.out.println(name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> names = Arrays.asList("Alice", "Bob", "Charlie", "Dave"); | |
names | |
.filter(e -> e.length() >= 4) | |
.forEach(e -> { System.out.println(e); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> names = Arrays.asList("Alice", "Bob", "Charlie", "Dave"); | |
names | |
.mapped(e -> { return e.length(); }) | |
.asIterable() // returns an Iterable of BiValue elements | |
// an element's key is the person's name, its value is the string length | |
.filter(e -> e.getValue() >= 4) | |
.sorted((a, b) -> a.getValue() - b.getValue()) | |
.forEach(e -> { System.out.println(e.getKey() + '\t' + e.getValue()); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Factory<Biscuit> biscuitFactory = Biscuit::new; | |
Biscuit biscuit = biscuitFactory.make(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Accessor<BEAN, PROPERTY> { | |
PROPERTY access(BEAN bean); | |
} | |
public static void main(String[] args) { | |
Address address = new Address("29 Acacia Road", "Tunbridge Wells"); | |
Accessor<Address, String> accessor = Address::getCity; | |
System.out.println(accessor.access(address)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
executorService.submit(MethodReference::sayHello); | |
private static void sayHello() { | |
System.out.println("hello"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Arrays.asList("Alice", "Bob", "Charlie", "Dave").forEach(System.out::println); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Queue { | |
Message read(); | |
void delete(Message message); | |
void deleteAll() default { | |
Message message; | |
while ((message = read()) != null) { | |
delete(message); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface BatchQueue extends Queue { | |
void setBatchSize(int batchSize); | |
void deleteAll() default { | |
setBatchSize(100); | |
Queue.super.deleteAll(); | |
} | |
} |