T - Type held inside closed varpublic class MutableLong
extends java.lang.Object
implements java.util.function.LongSupplier
String var = "hello";
Runnable r = () -> var ="world";
Won't compile because var is treated as if it is final.
This can be 'worked around' by using a wrapping object or array.
e.g.
Mutable<String> var = Mutable.of("hello");
Runnable r = () -> var.set("world");
| Constructor and Description |
|---|
MutableLong() |
| Modifier and Type | Method and Description |
|---|---|
long |
getAsLong() |
MutableLong |
mutate(java.util.function.LongFunction<java.lang.Long> varFn) |
static MutableLong |
of(long var)
Create a Mutable variable, which can be mutated inside a Closure
e.g.
|
MutableLong |
set(long var) |
public static MutableLong of(long var)
Mutable<Integer> num = Mutable.of(20);
Stream.of(1,2,3,4).map(i->i*10).peek(i-> num.mutate(n->n+i)).foreach(System.out::println);
System.out.println(num.get());
//prints 120
var - Initial value of Mutablepublic long getAsLong()
getAsLong in interface java.util.function.LongSupplierpublic MutableLong set(long var)
var - New valuepublic MutableLong mutate(java.util.function.LongFunction<java.lang.Long> varFn)
varFn - New value