Created
September 6, 2017 14:58
-
-
Save SirEdvin/c9d6e20574072b4b73b9c7165f6d7714 to your computer and use it in GitHub Desktop.
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
import java.lang.Math; | |
import java.util.function.BinaryOperator; | |
import java.io.*; | |
// one class needs to have a main() method | |
public class Test | |
{ | |
// arguments are passed using the text field below this editor | |
public static void main(String[] args) throws IOException | |
{ | |
BinaryOperator<String> adder1 = (n1, n2) -> n1 + n2; | |
BinaryOperator<String> adder2 = (BinaryOperator<String> & Serializable)((n1, n2) -> n1 + n2); | |
System.out.println(adder1.getClass().getInterfaces()); | |
System.out.println(adder2.getClass().getInterfaces()); | |
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(new File("lambdas"))); | |
try { | |
output.writeObject(adder1); | |
} catch (java.io.NotSerializableException e){ | |
System.out.println("As expected"); | |
} | |
output.writeObject(adder2); | |
output.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment