update meth ref ex
This commit is contained in:
parent
8eb2262b0c
commit
c0f72ffa88
|
@ -5,9 +5,10 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class MethodReferenceExamples {
|
public class MethodReferenceUnitTest {
|
||||||
|
|
||||||
private static <T> void doNothingAtAll(Object... o) {
|
private static <T> void doNothingAtAll(Object... o) {
|
||||||
}
|
}
|
||||||
|
@ -17,10 +18,8 @@ public class MethodReferenceExamples {
|
||||||
@Test
|
@Test
|
||||||
public void referenceToStaticMethod() {
|
public void referenceToStaticMethod() {
|
||||||
List<String> messages = Arrays.asList("Hello", "Baeldung", "readers!");
|
List<String> messages = Arrays.asList("Hello", "Baeldung", "readers!");
|
||||||
messages.forEach((word) -> {
|
messages.forEach(word -> StringUtils.capitalize(word));
|
||||||
System.out.println(word);
|
messages.forEach(StringUtils::capitalize);
|
||||||
});
|
|
||||||
messages.forEach(System.out::println);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -63,7 +62,7 @@ public class MethodReferenceExamples {
|
||||||
@Test
|
@Test
|
||||||
public void limitationsAndAdditionalExamples() {
|
public void limitationsAndAdditionalExamples() {
|
||||||
createBicyclesList().forEach(b -> System.out.printf("Bike brand is '%s' and frame size is '%d'%n", b.getBrand(), b.getFrameSize()));
|
createBicyclesList().forEach(b -> System.out.printf("Bike brand is '%s' and frame size is '%d'%n", b.getBrand(), b.getFrameSize()));
|
||||||
createBicyclesList().forEach((o) -> MethodReferenceExamples.doNothingAtAll(o));
|
createBicyclesList().forEach((o) -> MethodReferenceUnitTest.doNothingAtAll(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Bicycle> createBicyclesList() {
|
private List<Bicycle> createBicyclesList() {
|
Loading…
Reference in New Issue