Last active
June 28, 2020 16:02
-
-
Save ashkrit/5f3068ec4f3613e09c419b20884a2774 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
| @Test() | |
| public void save_function_works() throws Exception { | |
| // Addtional casting allow to mark as serilized | |
| Function<String, String> upper = (Function<String, String> & Serializable) x -> x.toUpperCase(); | |
| try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
| ObjectOutputStream os = new ObjectOutputStream(bos)) { | |
| os.writeObject(upper); | |
| try (ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); | |
| ObjectInputStream in = new ObjectInputStream(bis)) { | |
| Function<String, String> restoredUpper = (Function<String, String>) in.readObject(); | |
| Assertions.assertEquals("FAAS", restoredUpper.apply("FaaS")); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment