I am using a generic class TestThrows< T >
with a containing function that returns a generic list . My problem is i am unable to compile this program and it is throwing following error :
Type mismatch: cannot convert from element type Object to Throwable
public class Test
{
public static void main( String[] args )
{
TestThrows testThrows = new TestThrows();
// compile error on the next line
for ( Throwable t : testThrows.getExceptions() )
{
t.toString();
}
}
static class TestThrows< T >
{
public List< Throwable > getExceptions()
{
List< Throwable > exceptions = new ArrayList< Throwable >();
return exceptions;
}
}
}
I am not sure why is this error as i am using generic list ?