Package javascalautils.concurrent
Class PromiseCompanion
- java.lang.Object
-
- javascalautils.concurrent.PromiseCompanion
-
public final class PromiseCompanion extends java.lang.Object
Acts as a Scala type companion object forPromise
.
The primary purpose is to get the Scala feel of instantiating classes.
In Scala you can define a companion object for a class, acting as a static reference/singleton for that class allowing you do define factory methods.
One use case is to define methods with the same name as the class and let these methods invoke the constructor thus creating a nice way to create instances without using the word "new".
This can be achieved in java by statically importing a method and then using it.
The limitation is that classes may not have method with the same name as the class itself hence new companion classes have to be created.
To be able to use it in a neat concise way one needs to statically import the method.import static javascalautils.PromiseCompanion.Promise; Promise<String> promise = Promise();
- Since:
- 1.3
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Promise<T>
Promise()
Creates an instance of Promise.
-
-
-
Method Detail
-
Promise
public static <T> Promise<T> Promise()
Creates an instance of Promise.
Best used in conjunction with statically importing this method.import static javascalautils.concurrent.FutureCompanion.Promise; Promise<String> promise = Promise();
- Type Parameters:
T
- The type the Promise is expected to deliver- Returns:
- The Promise instance
- Since:
- 1.3
-
-