Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create non-optional-returning as functions for superclasses/extended interfaces #20

Open
DougGregor opened this issue Sep 30, 2024 · 1 comment
Labels

Comments

@DougGregor
Copy link
Member

AnyJavaObject provides an as method that performs a dynamic cast to another AnyJavaObject-conforming type, then returns an optional with either the casted type or nil to indicate failure.

When casting to the superclass type or the type of one of the interfaces that a type extends, the result will never be nil. Developers performing these upcasts will have to force-unwrap these results. For example:

let throwable: Throwable = ...
let object: JavaObject = throwable.as(JavaObject.self)!

As part of generating the Throwable Swift type, we could provide non-optional-returning overloads of as, e.g.,

@JavaClass("java.lang.Throwable")
struct Throwable {
  func as(_: JavaObject.Type) -> JavaObject { ... }
}
@DougGregor DougGregor changed the title Create non-optional-returning as functions for superclasses/ Create non-optional-returning as functions for superclasses/extended interfaces Sep 30, 2024
@DougGregor DougGregor added the good first issue Good for newcomers label Sep 30, 2024
@AbdAlRahmanGad
Copy link
Contributor

Hi @DougGregor,
Could you assign this issue to me?
Could you also point me to which file I should implement this change inside?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants