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

GenericType don't work if they are created in a parameterized class #2305

Closed
hgschmie opened this issue Mar 24, 2023 · 1 comment · Fixed by #2306
Closed

GenericType don't work if they are created in a parameterized class #2305

hgschmie opened this issue Mar 24, 2023 · 1 comment · Fixed by #2306

Comments

@hgschmie
Copy link
Contributor

Things that make one cry:

 @Test
    void thisWorks() {

        class Foo {
            Type getType() {
                return new GenericType<List<String>>() {}.getType();
            }
        }

        assertThat (new Foo().getType()).isNotNull();
    }

    @Test
    void thisDoesNot() {

        class Foo<T> {
            Type getType() {
                return new GenericType<List<String>>() {}.getType();
            }
        }

        assertThat (new Foo<>().getType()).isNotNull();
    }

This seems to be a bug in geantryref.

@hgschmie
Copy link
Contributor Author

hgschmie commented Mar 24, 2023

similar code with geantryref classes works fine:

  public void testWorks() {

    class Foo {
      Type getType() {
        return new TypeToken<List<String>>() {}.getType();
      }
    }

    assertNotNull(new Foo().getType());
  }

  public void testDoesNotWork() {

    class Foo<T> {
      Type getType() {
        return new TypeToken<List<String>>() {}.getType();
      }
    }

    assertNotNull(new Foo<>().getType());
  }

This is some quirk in the GenericTypes implementation which is different from what is in geantryref.

hgschmie added a commit to hgschmie/jdbi that referenced this issue Mar 24, 2023
Port the code from geantryref.TypeToken#extractType for classes passed
into GenericType.

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

Successfully merging a pull request may close this issue.

1 participant