I have a class PictureArrayAdapter that extends ArrayAdapter<Pair<String, ImageInitialiser>> and has the following constructor:
public PictureArrayAdaptor(Context context, Pair<String, ImageInitialiser>[] values)
We have explicitly declared that when this constructor is called, the programmer has to pass a Pair<String, ImageInitialiser>[], otherwise a type error may occur. Now, producing such an object without a warning is rather difficult:
@SuppressWarnings("unchecked")
Pair<String, ImageInitialiser> tableData[] = new Pair[1];
tableData[0]=new Pair<String, ImageInitialiser>("A", new ResourceImageInitialiser(R.drawable.sample1));
One possibility would be to use a list instead. However, for the sake of consistency, I’d like to keep all the constructors exactly the same as the base class. Is there a nicer way of calling this constructor? I really don’t think that this is how it is supposed to be called.
Another approach is to create a class that extends Pair, for example
NamedImage is now a reifiable type so you can use arrays like
NamedImage[]with impunity. In addition, it gets rid of unchecked exceptions and simplifies all your declarations so that they no longer have nested type parameters.