import java.io.*; import java.util.*; public class LS { public static void main(String[] args) throws Exception { try { // Write lambdas out ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(baos); write(out, HashMap::new ); out.flush(); out.close(); // Read them back ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream in = new ObjectInputStream(bais); readIt(in); in.close(); } catch (IOException e) { e.printStackTrace(); throw e; } } static void write(ObjectOutput out, LSI lamb) throws IOException { out.writeObject(lamb); } static void readIt(ObjectInputStream in) throws IOException, ClassNotFoundException { LSI ls = (LSI) in.readObject(); Map result = ls.convert(); System.out.printf("Result: %s\n", result.getClass()); } } interface LSI extends Serializable { Map convert(); }