Skip to content

Commit e0181a1

Browse files
authored
Apply suggestions from code review
1 parent 795a8f4 commit e0181a1

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

‎Sources/SwiftJavaDocumentation/Documentation.docc/SupportedFeatures.md‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
403403
A 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
405405
exposes 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
414414
value's dynamic Swift type is exactly that type, in which case you receive a fresh binding
415415
registered in the given arena; otherwise the result is `Optional.empty()`.
416416

@@ -421,7 +421,6 @@ by a concrete `EnglishGreeter`:
421421
try (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
434433
the 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

‎SwiftKitCore/src/main/java/org/swift/swiftkit/core/SwiftDowncastable.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
public interface SwiftDowncastable {
2626

2727
/**
28-
* Swift {@code as?}: attempt to recover {@code type} — a non-generic concrete
29-
* jextracted Swift type — from this value.
28+
* Swift {@code as?}: attempt type-cast this instance to {@code T},
29+
* which must be a non-generic concrete jextracted Swift wrapper type.
3030
*
31-
* @return the recovered instance, or {@link Optional#empty()} if this value's
32-
* dynamic type is not {@code type}, if this value is not backed by a Swift value
33-
* (e.g. a Java-implemented conformer), or if {@code type} is not a concrete
31+
* @return the type-casted instance, or {@link Optional#empty()} if this value's
32+
* dynamic type is not {@code T}, if this value is not backed by a Swift value
33+
* (e.g. a Java-implemented conformer), or if {@code T} is not a concrete
3434
* jextracted type.
3535
*/
3636
default <T extends JNISwiftInstance> Optional<T> as(Class<T> type, SwiftArena arena) {

0 commit comments

Comments
 (0)