Is it possible (or even advisable) to cast the element retrieved from a for each statement in the statement itself? I do know that each element in list will be of type <
If you are not partial to Google collections, you can wrap the list with transform
method. In your case it will be very efficient and totally compliant. I would put it as a wrapper method though as Brian has suggested.
public List< SubType > fromDao ( )
{
// Put a comment for maintainer
// Lists from DAO always contain SubTypes
return
Lists.transform(
DAO.getList( ),
new Function< BaseType, SubType >( )
{
public SubType apply ( final BaseType from )
{
return (SybType) from;
}
};
}