@@ -401,16 +401,16 @@ the generated box, and composite returns are not extracted.
401401> Note: Downcasting returned protocol values is currently only supported in JNI mode.
402402
403403A value returned as ` any P ` / ` some P ` preserves its concrete dynamic type, so it can be
404- recovered — the equivalent of Swift's ` as? ` . Every imported protocol ` interface ` therefore
404+ recovered; This is equivalent to Swift's ` as? ` , of a checked ` instanceof ` cast in Java . Every imported protocol ` interface ` therefore
405405exposes an ` as ` method:
406406
407407``` java
408408< T extends JNISwiftInstance > Optional<T > as(Class<T > type, SwiftArena arena);
409409< T extends JNISwiftInstance > Optional<T > as(Class<T > type); // uses the default arena
410410```
411411
412- ` type ` must be a concrete jextracted type (a ` class ` , ` struct ` , or ` enum ` binding — the
413- ` JNISwiftInstance ` bound enforces this at compile time). The cast succeeds only when the
412+ ` type ` must be a concrete jextracted type.
413+ The cast succeeds only when the
414414value's dynamic Swift type is exactly that type, in which case you receive a fresh binding
415415registered in the given arena; otherwise the result is ` Optional.empty() ` .
416416
@@ -421,7 +421,6 @@ by a concrete `EnglishGreeter`:
421421try (var arena = SwiftArena . ofConfined()) {
422422 Greeter greeter = MySwiftLibrary . makeEnglishGreeter(" World" , arena);
423423
424- // Recover the concrete type — its `struct`-only members become available:
425424 Optional<EnglishGreeter > english = greeter. as(EnglishGreeter . class, arena);
426425 assertEquals(" World" , english. orElseThrow(). getName());
427426
@@ -430,9 +429,9 @@ try (var arena = SwiftArena.ofConfined()) {
430429}
431430```
432431
433- The cast returns ` Optional. empty() ` — rather than throwing — whenever it cannot apply: when
432+ The cast returns an empty optional if the cast fails, which might happen when
434433the dynamic type differs, when ` type ` is not a concrete jextracted type (e.g. a generic type
435- or another protocol), or when the receiver is not backed by a wrapped Swift value .
434+ or another protocol).
436435
437436### Swift closures
438437
0 commit comments