Multiple generic arrays
is it possible to create something like <String, Integer>[] a;
If I wanted to create an array that stores objects of String and Integer?

3 Years
Discussion Span
Last Post by jwenting

I don't know of any way (others may know better?), but I'm curious as to why you want to do that. You will still need to test and cast anything you get from the array because String's methods and Integer's methods are so different.
Depending on why you are doing it, it may be a good representation to have a wrapper class for your data, like

class MyDataStringOrInt {
   private String s; private int i;
   public MyDataStringOrInt(String stringValue) { ...
   public MyDataStringOrInt(int intValue) { ...
   public boolean isString() { ...
   public boolean isInt() { ...
   public String getStringValue() { ...

yes and no.
Creating something like

<E extends Object>[] arr;

might work (I've not tested this, not interested), but isn't really useful as you might as well write

Object[] arr;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.