[vector] Remove generics from Vector.Shape
Paul Sandoz
paul.sandoz at oracle.com
Tue Jan 30 00:13:27 UTC 2018
Hi,
The generics of Vector are a little awkward, stemming from Vector.Shape:
public interface Vector<E, S extends Vector.Shape<Vector<?, ?>>> {
interface Species<E, S extends Vector.Shape<Vector<?, ?>>> {
interface Mask<E, S extends Shape<Vector<?, ?>>> {
interface Shuffle<E, S extends Shape<Vector<?, ?>>> {
interface Shape<V extends Vector<?, ?> /*extends Vector<?, Shape<V>>*/> {
It's not clear to me why Shape needs to have any type variable which is bound to Vector.
- There are no methods on Shape that depend on Vector.
- We cannot bind more specific shapes types to only be applicable to more specific vector types.
- Factory methods should be responsible for obtaining a Species given a Class and Shape. It’s a runtime query as to whether a combination of the class and shape can produce a required Species from which Vector instances can be created. (Same applies to casting/resizing/reshaping).
Therefore i propose:
public interface Vector<E, S extends Vector.Shape> {
interface Species<E, S extends Vector.Shape> {
interface Mask<E, S extends Shape> {
interface Shuffle<E, S extends Shape> {
interface Shape {
Methods accepting or returning Vector/Species etc generic in shape then become less imposing e.g.:
- static <E, S extends Vector.Shape<Vector<?, ?>>> Vector.Species<E, S> speciesInstance(Class<E> c, S s) {
+ static <E, S extends Vector.Shape> Vector.Species<E, S> speciesInstance(Class<E> c, S s) {
Vector.Species<E, S> res = null;
- Vector.Species<?, Vector.Shape<Vector<?, ?>>> species =
+ Vector.Species<?, Vector.Shape> species =
Vector.preferredSpeciesInstance(box);
- static <S extends Vector.Shape<Vector<?, ?>>> int mismatch(byte[] a, byte[] b, ByteVector.ByteSpecies<S> species) {
+ static <S extends Vector.Shape> int mismatch(byte[] a, byte[] b, ByteVector.ByteSpecies<S> species) {
Paul.
More information about the panama-dev
mailing list