returning a new object from an array

so I am wanting to return a new object of the object type that is in an array. Is it possible, for example of waht I want to do objecta[] as = new objecta[1]; return new objecta[1]

what if im attempting to do it to an abstract ?

I can’t tell exactly what you mean, is it something like this? http://stackoverflow.com/questions/529085/how-to-generic-array-creation

I have a super Tile() which has subclasses such as space and hull etc the Tiles[] arraystores the subclasses as objects, how would I return a new one.

Why not have a [icode]Class<? extends Tile>[][/icode] ? Then you can just tiles[3].newInstance();

There’s probably a better solution, but to keep your array format, this is what I would do.

Pls don’t use reflection in this way.
One better solution would be to use factories. Factories are Objects/Classes which know how to instantiate a specific Object.

I don’t know why you want to store these factories in an array, but you could use Enums for example:


interface Factory<E>
{
  E create();
}

enum TileFactories implements Factory<Tile>
{
   GRASS {
      Tile create(){ return new GrassTile(); }
   },
   ROCK {
      Tile create(){ return new RockTile(); }
   },
   SPECIAL_ROCK {
      Tile create(){ 
        RockTile t  = new RockTile(); 
        t.setSpezial(true);
        return t;
      }
   }
}


Tile t = TileFactories.getValues()[1].create();