It makes me wonder how they are dealing with memory management when Java objects are being used from Swift
It uses Swift macros to add a `JavaObjectHolder` property to Swift types annotated with `@JavaClass`[0]. `JavaObjectHolder` is a Swift class that takes a global JNI reference to the Java object, and releases it when the holder is destroyed[1].
The result is that a codegen utility emits Swift structs[2] that wrap the JNI values, and the JNI glue code for method invocation is applied at compile-time when the macros are expanded.
Comments
It uses Swift macros to add a `JavaObjectHolder` property to Swift types annotated with `@JavaClass`[0]. `JavaObjectHolder` is a Swift class that takes a global JNI reference to the Java object, and releases it when the holder is destroyed[1].
The result is that a codegen utility emits Swift structs[2] that wrap the JNI values, and the JNI glue code for method invocation is applied at compile-time when the macros are expanded.
[0] https://github.com/swiftlang/swift-java/blob/e7d7a217e37d49b...
[1] https://github.com/swiftlang/swift-java/blob/main/Sources/Ja...
[2] https://github.com/swiftlang/swift-java/blob/main/Sources/Ja...