Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
List <String> list = new ArrayList<String>(); list.trimToSize();
由于trimToSize()只出现在界面中ArrayList,而不出现在List界面中,如果我实例化为一个interface而不是一个具体的类,这是丢失的功能之一吗?
trimToSize()
ArrayList
List
interface
您只能调用您正在调用的类型提供的方法。如果您想调用该trimToSize( )方法,那么您需要先list转换为ArrayList:
trimToSize( )
list
( (ArrayList) list ).trimToSize( );