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

Structures with generic fields not working #59

Open
ctrimble opened this issue Mar 31, 2015 · 0 comments
Open

Structures with generic fields not working #59

ctrimble opened this issue Mar 31, 2015 · 0 comments

Comments

@ctrimble
Copy link
Contributor

BridJ cannot properly handle structs with nested generic types. For instance, the following test case will not work:

package org.bridj;

import org.bridj.ann.Field;
import org.junit.Test;

public class GenericStructTest {
  // a structure to nest.
  public static class Nested extends StructObject {
    @Field(0)
    public int data() {
      return io.getIntField(this, 0);
    }

    @Field(0)
    public Nested data(int data) {
      io.setIntField(this, 0, data);
      return this;
    }
  }

  // a type with a generic nested structure.
  public static class GenericStruct<N extends StructObject> extends
      StructObject {
    @Field(0)
    public N nested() {
      return io.getNativeObjectField(this, 0);
    }

    @Field(0)
    public GenericStruct<N> nested(N nested) {
      io.setNativeObjectField(this, 0, nested);
      return this;
    }
  }

  // a concrete structure. BridgJ cannot allocate this type.
  public static class ConcreteStruct extends GenericStruct<Nested> {
  }

  @Test
  public void canCreatePointerToExtendedGenericStruct() {
    Pointer.allocate(ConcreteStruct.class).release();
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant