Skip to content

Instantly share code, notes, and snippets.

@SirEdvin
Created September 6, 2017 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SirEdvin/c9d6e20574072b4b73b9c7165f6d7714 to your computer and use it in GitHub Desktop.
Save SirEdvin/c9d6e20574072b4b73b9c7165f6d7714 to your computer and use it in GitHub Desktop.
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