> > MemoizingSupplier is keeping the delegate forever. > NonSerializableMemoizingSupplier is releasing the delegate (delegate = > null) when the value is captured because it's not needed anymore.
yes, that's pretty clear from the code. That's why one is final and the other volatile. and this one is not. For me it seems that final serves the purpose of safe initialization in case that another thread which is actually "initializing"(calls get() method on an instance of a MemozingSupplier) could properly see a delegate. And in case of NonSerializableMemoizingSupplier volatile seems to do the same thing. Does final adds any special properties over volatile than an object is serialized? On Thu, Aug 27, 2020 at 3:58 PM Henri Tremblay <[email protected]> wrote: > MemoizingSupplier is keeping the delegate forever. > NonSerializableMemoizingSupplier is releasing the delegate (delegate = > null) when the value is captured because it's not needed anymore. > > That's why one is final and the other volatile. > > Why they are not behaving the same way is a good question. > > On Thu, 27 Aug 2020 at 07:18, SuperNunrg <[email protected]> wrote: > >> >> Thank you all for answers. Let me ask one more question here. >> Guava has a lot of useful classes such as >> >> https://github.com/google/guava/blob/master/guava/src/com/google/common/base/Suppliers.java >> there are two classes MemoizingSupplier and >> NonSerializableMemoizingSupplier >> the first one has delegate marked as final and second as volotile. Why is >> that? could NonSerializableMemoizingSupplier has its delegate marked as >> final? >> has it something to do with GC? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "mechanical-sympathy" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web, visit >> https://groups.google.com/d/msgid/mechanical-sympathy/69a4dd6c-8f15-47b7-936c-17761b481df6o%40googlegroups.com >> <https://groups.google.com/d/msgid/mechanical-sympathy/69a4dd6c-8f15-47b7-936c-17761b481df6o%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- > You received this message because you are subscribed to the Google Groups > "mechanical-sympathy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web, visit > https://groups.google.com/d/msgid/mechanical-sympathy/CADZL2%3DtjuFFn9pPMBApmG8dVZ5CNNNetEXogZ1H9%2BjyuUU9%2B3w%40mail.gmail.com > <https://groups.google.com/d/msgid/mechanical-sympathy/CADZL2%3DtjuFFn9pPMBApmG8dVZ5CNNNetEXogZ1H9%2BjyuUU9%2B3w%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web, visit https://groups.google.com/d/msgid/mechanical-sympathy/CAJ183RNmFDBYA3HqOjrwHHiiQJ-OAbKc1x8YrZ1n9uMYnkSHVg%40mail.gmail.com.
