-
I want to persist a Function using EclipseStore. It is persisted successfully: But when restarting the application I get the following exception:
How can I get this to work? Thank you for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Unfortunately, you can not. While, in theory, Lambdas are serializable, the JVM cannot guarantee that they will be restored properly because they don't have a unique name like classes but just contiguous numbers. For example given following code class Foo
{
Consumer<String> printer = System.out::println;
} If you store an instance of class Foo
{
void someCode()
{
Consumer<String> something = (str) -> someAction(str);
}
Consumer<String> printer = System.out:println;
} After restoring the It doesn't work with the built-in Java serializer as well. https://docs.eclipsestore.io/manual/storage/addendum/supported-java-features.html#_java_8 |
Beta Was this translation helpful? Give feedback.
Unfortunately, you can not.
While, in theory, Lambdas are serializable, the JVM cannot guarantee that they will be restored properly because they don't have a unique name like classes but just contiguous numbers.
For example given following code
If you store an instance of
Foo
, then change the code to this:After restoring the
Foo
instance, the value forprinter
would be thesomething
function because it has the first position in the code now.It doesn't work with …