public class Box<R> extends java.lang.Object implements Lazy<R>
Java values and primitives can be put in boxes to make them lazy. This should use less
memory than Thunk
s, and may also avoid auto(un)boxing for primitives.
The method Thunk.lazy(boolean)
will create appropriate boxes.
Modifier and Type | Class and Description |
---|---|
static class |
Box.B |
static class |
Box.C |
static class |
Box.D |
static class |
Box.F |
static class |
Box.I |
static class |
Box.L |
static class |
Box.O
O, like in "octet", since B already used for booleans
|
static class |
Box.S |
Modifier and Type | Method and Description |
---|---|
Thunk<R> |
asThunk()
Tell if this is really a
Thunk |
R |
call()
Compute the value if it is needed.
|
boolean |
isShared()
Tell if this is shared.
|
final R item
public Box(R it)
public boolean isShared()
Lazy
Tell if this is shared.
Data and functions whose Lazy.call()
method returns this as well
as simple boxes that just hold a value ready to be supplied and Thunk
s
are considered shared.
But a bare lambda expression is assumed to be in need of sharing. For example:
() -> 42