ArrayList<String>.class
is a construct not supported by Java compiler.
For you first try, you should do this:
@SuppressWarnings( "unchecked" )
ArrayList<String> mocked = mock(ArrayList.class);
This happens because mock
method can only return a raw type. In general it is not good to use the raw types because this may lead to runtime errors. In your case it's perfectly fine, because you know that mocked
is not a REAL ArrayList<String>
anyway.
Just a general advise about @SuppressWarnings( "unchecked" )
annotation. Try to keep it as close to the source of the problem as possible. For example you may put it just for the variable declaration, or you can suppress it for the whole method. In general suppress it for a variable, because otherwise the broad method annotation can suppress other problems in your function.