Reputation: 23443
List <String> list = new ArrayList<String>();
list.trimToSize();
Since trimToSize()
appears only in ArrayList
, and not in the List
interface, is this one of the features lost if i instantiate to an interface
instead of a concrete class?
Upvotes: 1
Views: 128
Reputation: 25799
You can only call the methods provided by the type you're calling on. If you wanted to call the trimToSize( )
method then you'd need to first cast list
to ArrayList
:
( (ArrayList) list ).trimToSize( );
Upvotes: 2