[ 
https://issues.apache.org/jira/browse/GROOVY-11993?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniel Sun updated GROOVY-11993:
--------------------------------
    Description: 
Groovy has supported serializable lambda expression for years, and serializable 
method reference will be supported in this improvement, e.g.


{code}
            import java.io.ByteArrayInputStream
            import java.io.ByteArrayOutputStream
            import java.io.Serializable

            @CompileStatic
            class C {
                interface SerSupplier<T> extends Serializable, Supplier<T> {}

                private final String text

                C(String text) {
                    this.text = text
                }

                SerSupplier<String> create() {
                    text::trim
                }

                static byte[] serialize(Serializable value) {
                    def out = new ByteArrayOutputStream()
                    out.withObjectOutputStream { it.writeObject(value) }
                    out.toByteArray()
                }

                static <T> T deserialize(byte[] bytes) {
                    new 
ByteArrayInputStream(bytes).withObjectInputStream(C.classLoader) {
                        (T) it.readObject()
                    }
                }
            }

            C.SerSupplier<String> supplier = C.deserialize(C.serialize(new C('  
answer  ').create()))
            assert supplier instanceof Serializable
            assert supplier.get() == 'answer'
{code}

> Support serializable method reference
> -------------------------------------
>
>                 Key: GROOVY-11993
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11993
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Daniel Sun
>            Priority: Major
>
> Groovy has supported serializable lambda expression for years, and 
> serializable method reference will be supported in this improvement, e.g.
> {code}
>             import java.io.ByteArrayInputStream
>             import java.io.ByteArrayOutputStream
>             import java.io.Serializable
>             @CompileStatic
>             class C {
>                 interface SerSupplier<T> extends Serializable, Supplier<T> {}
>                 private final String text
>                 C(String text) {
>                     this.text = text
>                 }
>                 SerSupplier<String> create() {
>                     text::trim
>                 }
>                 static byte[] serialize(Serializable value) {
>                     def out = new ByteArrayOutputStream()
>                     out.withObjectOutputStream { it.writeObject(value) }
>                     out.toByteArray()
>                 }
>                 static <T> T deserialize(byte[] bytes) {
>                     new 
> ByteArrayInputStream(bytes).withObjectInputStream(C.classLoader) {
>                         (T) it.readObject()
>                     }
>                 }
>             }
>             C.SerSupplier<String> supplier = C.deserialize(C.serialize(new 
> C('  answer  ').create()))
>             assert supplier instanceof Serializable
>             assert supplier.get() == 'answer'
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to