Repository navigation
JNI: bridge protocol requirement defaults to Java interface methods - #11
Merged
teamhimeh merged 1 commit intoOct 23, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
JNI callback interfaces currently leave every protocol requirement abstract, even when Swift supplies an unconditional implementation in an extension. Java implementors must repeat that implementation instead of inheriting the Swift behavior.
For example:
With this change,
greeting()is a Java interfacedefaultmethod that forwards to the Swift implementation. Java only needs to implementname():The Swift body remains the implementation. Its calls to other requirements dispatch to the original Java receiver, preserving Java overrides of other defaulted methods.
Changes
Int/Javalongconversion and the generated Java method's exception declaration during callbacks.Scope
Default bridges require Java callbacks to be enabled and a callback-compatible protocol with synchronous, nongeneric instance-method requirements. Conditional implementations, attributed declarations (including global-actor isolation), property requirements, and extension-only convenience members remain outside this feature.
If every abstract method acquires a default, the Java interface is no longer functional; callers can use an anonymous implementation instead of a lambda. Existing Swift-backed boxes continue to dispatch their original witnesses.
The base branch must already distinguish protocol-body requirements from extension members and preserve inherited requirement names consistently.
Validation
swift test --disable-experimental-prebuilts --disable-sandbox: full Swift test suite passed../gradlew :Samples:SwiftJavaExtractJNISampleApp:test --no-daemon: all 290 Java tests passed with no failures or skips. New runtime coverage exercises inherited defaults, Java overrides of other defaults, exceptions, nested protocols, and refined protocols.swift-format lint --stricton changed Swift files andgit diff --checkpassed.Tested with Apple Swift 6.4 and JetBrains Runtime 25 on macOS.