Bytecoder icon indicating copy to clipboard operation
Bytecoder copied to clipboard

Native constructors

Open ogrammer opened this issue 4 years ago • 2 comments

This issue is a suggestion. At the moment it is not possible to instantiate JavaScript classes from Java without using static native methods, an annotation for this purpose would be nice to have.

public class ArrayBuffer implements OpaqueReferenceType {
	@NativeConstructor("create")
	public ArrayBuffer(int size) {}
}
bytecoder.imports.arraybuffer = {
	create: function (...) { ... }
};
new ArrayBuffer(4);

ogrammer avatar Nov 18 '19 15:11 ogrammer

This is a very useful feature request. Thank you for submitting this!

mirkosertic avatar Nov 18 '19 18:11 mirkosertic

Now that I think about it, instantiating abstract classes directly isn't possible. However, if using @OpaqueMethod/Property works with native methods then this shouldn't be a problem as one could use non-abstract classes instead.

ogrammer avatar Nov 26 '19 13:11 ogrammer

Closed due to no further feedback.

mirkosertic avatar Mar 29 '23 16:03 mirkosertic