public abstract class AutoCompletable extends Completable implements AutoCloseable
completed
status, allowing objects to
differentiate between an initialization phase and their final value.
In addition to Completable
it implements AutoCloseable
to
allow simplified factory methods using try-with-resource statement.
Each getter is recommended to call #complete()
, while setters must
call #throwIfCompleted()
prior to modification.
Before using AutoCompletable
think about using either a streamlined
constructor or a builder class.
Example: SomeFancyThing
is of type AutoCloseable
. The
method getSomeFancyThing()
is meant to initialize
SomeFancyThing
while it should no longer be modifiable outside that
method.
SomeFancyThing getSomeFanyThing() { try (SomeFancyThing someFanyThing = new SomeFancyThing()) { ... return someFanyThing; } }
Constructor and Description |
---|
AutoCompletable() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Calls
Completable.complete() to finish the objects initialization
phase. |
complete, isCompleted, throwIfCompleted
public void close()
Completable.complete()
to finish the objects initialization
phase.close
in interface AutoCloseable
Copyright © 2025. All rights reserved.