Pointer implements Closeable { @Nonnull public Pointer<Pointer<T>> castpp() { return wrap(new ParameterizedType() { @Override public Type[] getActualTypeArguments() { return new Type[]{Pointer.this.type}; } @Override public Type getRawType() { return Pointer.class; } @Override public Type getOwnerType() { return null; } }, this.address, false); } Pointer(@Nonnull final Type type,
            final long address,
            final boolean autoFree,
            final int typeSize); @Nonnull static Pointer<Void> wrap(@Nonnull final ByteBuffer byteBuffer); @Nonnull static Pointer<U> wrap(@Nonnull final Class<U> type,
                                      @Nonnull final ByteBuffer byteBuffer); @Nonnull static Pointer<Void> wrap(final long address); @Nonnull static Pointer<U> wrap(@Nonnull final Class<U> type,
                                      final long address); static Pointer<Void> realloc(@Nonnull Pointer<?> pointer,
                                        @Nonnegative final int size); static Pointer<U> realloc(@Nonnull Pointer<?> pointer,
                                         @Nonnegative final int size,
                                         @Nonnull final Class<U> type); @Nonnull static Pointer<Void> malloc(@Nonnegative final int size); @Nonnull static Pointer<U> malloc(@Nonnegative final int size,
                                        @Nonnull final Class<U> type); @Nonnull static Pointer<Void> calloc(@Nonnegative final int nmemb,
                                       @Nonnegative final int size); @Nonnull static Pointer<U> calloc(@Nonnegative final int nmemb,
                                        @Nonnegative final int size,
                                        @Nonnull final Class<U> type); @Nonnull static Pointer<CLong> nref(@Nonnull final CLong... val); static Pointer<Object> from(@Nonnull final Object val); @Nonnull static Pointer<U> ref(@Nonnull final U val); @SafeVarargs @Nonnull static Pointer<U> nref(@Nonnull final U... val); @SafeVarargs @Nonnull static Pointer<U> nref(@Nonnull final U... val); @Nonnull static Pointer<Byte> nref(@Nonnull final byte... val); @Nonnull static Pointer<Short> nref(@Nonnull final short... val); @Nonnull static Pointer<Integer> nref(@Nonnull final int... val); @Nonnull static Pointer<Float> nref(@Nonnull final float... val); @Nonnull static Pointer<Long> nref(@Nonnull final long... val); @Nonnull static Pointer<Double> nref(@Nonnull final double... val); @Nonnull static Pointer<String> nref(@Nonnull final String val); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); void close(); @Nonnull abstract T get(); @Nonnull abstract T get(@Nonnegative final int index); @Nonnull final Pointer<T> inc(); @Nonnull final Pointer<T> dec(); @Nonnull final Pointer<T> plus(final int value); @Nonnull final Pointer<T> minus(final int value); @Nonnull Pointer<U> castp(@Nonnull final Class<U> type); @Nonnull Pointer<Pointer<T>> castpp(); abstract void set(@Nonnull final T val); abstract void set(@Nonnegative final int index,
                             @Nonnull final T val); final long address; }
@Test public void testCastpp() throws Exception { final byte b0 = (byte) 0x8F; final byte b1 = 0x7F; final byte b2 = (byte) 0xF7; final byte b3 = 0x00; final byte b4 = 0x01; final long pointer = byteArrayAsPointer(b0, b1, b2, b3, b4); final long pointerOfPointer = pointerOfPointer(pointer); final long pointerOfPointerPointer = pointerOfPointer(pointerOfPointer); try (final Pointer<Pointer<Pointer<Byte>>> bytePointerPointer = wrap(Byte.class, pointerOfPointerPointer).castpp() .castpp(); final Pointer<Pointer> pointerPointer = wrap(Pointer.class, pointerOfPointer)) { assertThat(bytePointerPointer.get() .get() .get(4)).isEqualTo(b4); this.expectedException.expect(IllegalStateException.class); this.expectedException.expectMessage("Can not dereference void pointer."); pointerPointer.get() .get(); } }