Created
September 7, 2018 06:37
-
-
Save jelinski/57407dd687bd421655691c50dbe9e4a0 to your computer and use it in GitHub Desktop.
Draft for code that will be used to demonstrate how changing lambda to method reference can change the program behaviour
This file contains hidden or 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
package pl.jellysoft; | |
import org.junit.Test; | |
import java.util.Arrays; | |
public class MethodReferenceSemanticChangeTest { | |
// final will solve it | |
private BusinessObject businessObject = new BusinessObject(); | |
@Test | |
public void semanticChangeTest() { | |
//BusinessObject businessObject = new BusinessObject(); | |
Arrays.asList("One", "Two", "Three") | |
.forEach(o -> businessObject.print(o)); | |
// .forEach(businessObject::print); | |
} | |
private class BusinessObject { | |
Object getObject() { | |
return null; | |
} | |
void print(Object o) { | |
System.out.println(o.toString()); | |
businessObject = new BusinessObjectDifferentImpl(); | |
} | |
} | |
private class BusinessObjectDifferentImpl extends BusinessObject { | |
@Override | |
void print(Object o) { | |
super.print("Prefix:" + o); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment