Skip to content

Commit e7a85c2

Browse files
committed
Allow passing in a consumer (passing 'this') to the VM constructor to allow logic 'before the super()'
Workaround since we target 8
1 parent aba637d commit e7a85c2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Diff for: ssvm-core/src/main/java/dev/xdark/ssvm/VirtualMachine.java

+21
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import java.util.Map;
6161
import java.util.TreeMap;
6262
import java.util.concurrent.atomic.AtomicReference;
63+
import java.util.function.Consumer;
6364

6465
public class VirtualMachine implements VMEventCollection {
6566

@@ -94,6 +95,26 @@ public class VirtualMachine implements VMEventCollection {
9495
private volatile InstanceValue mainThreadGroup;
9596

9697
public VirtualMachine() {
98+
this(null);
99+
}
100+
101+
/**
102+
* Constructor for running some logic operating on {@code this}
103+
* before the VM internals are initialized.
104+
* <p/>
105+
* This allows sub-classes to set field values <i>(though non-final)</i>
106+
* which can then be used in the {@code createX} method implementations.
107+
* The consumer allows us to act on {@code this} <i>"before the super
108+
* constructor call".</i>
109+
*
110+
* @param consumer
111+
* Consumer to run before the VM internals are initialized.
112+
* @param <V>
113+
* Self type.
114+
*/
115+
@SuppressWarnings("unchecked")
116+
public <V extends VirtualMachine> VirtualMachine(Consumer<V> consumer) {
117+
if (consumer != null) consumer.accept((V) this);
97118
properties = createSystemProperties();
98119
env = createEnvironmentVariables();
99120
vmInterface = createVMInterface();

0 commit comments

Comments
 (0)