Organizational Research By

Surprising Reserch Topic

quick java question casting an array of objects into an array of my intended cl using -'java,collections,casting,object'


quick java question casting an array of objects into an array of my intended cl  using -'java,collections,casting,object'

Just for review, can someone quickly explain what prevents this from working (on compile):

private HashSet Data;

...

public DataObject[] getDataObjects( )
{
    return (DataObject[]) Data.toArray();
}


...and what makes this the way that DOES work:

public DataObject[] getDataObjects( )
{
    return (DataObject[]) Data.toArray( new DataObject[ Data.size() ] );
}


I'm not clear on the mechanism at work with casting (or whatever it is) that makes this so.
    
asked Sep 7, 2015 by rajesh
0 votes
4 views



Related Hot Questions



Government Jobs Opening


...