Skip to content

Correctly importing Optional::get() as -> T causes MethodNotFound #439

Closed

Description

@ktoso

We are now able to handle generics more properly in wrap-java and now we import Optional as:

@JavaClass("java.util.Optional")
open class JavaOptional<T: AnyJavaObject>: JavaObject {
  @JavaMethod
  open func get() -> T!

which then crashes

SwiftJava/JavaOptional.swift:2: Fatal error: 'try!' expression unexpectedly raised an error: java.lang.NoSuchMethodError: Ljava/util/Optional;.get()Ljava/lang/String;

so the String bit is coming unexpectedly because Swift sees the reified generic type as "String" and not "some T" therefore the downcall is forming an incorrect signature.

The problem is somewhere in the dynamicJavaMethodCall infra which can't handle the generic properly when forming the downcall signature

Activity

  1. added theissue type on Nov 12, 2025
  2. ktoso commented on Oct 5, 2026

    @ktoso
    CollaboratorAuthor

    Was fixed by #440

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions