Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: What's the best way to make a cross string set? Date: Mon, 31 Jul 2017 19:24:33 -0400 Organization: Aioe.org NNTP Server Lines: 36 Message-ID: References: <6f9ff338-1944-4b64-83b8-4a921ce57a89@googlegroups.com> <1c3dafe0-c2ed-4ea1-9c06-b069f20c16ea@googlegroups.com> NNTP-Posting-Host: PBuS014lhzVyHjLbXmo/ZQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:37039 On 7/31/2017 8:24 AM, Eric Douglas wrote: > You're saying declaring a variable as a List is more efficient even > if you know it's going to be instantiated as ArrayList? I've always > tried to avoid that because it's one more line in the import section, > and I never use * imports because that just sounds confusing at best > messy at worst when you get into the same class names in multiple > packages. List lst = new ArrayList(); is often considered better than: ArrayList lst = new ArrayList(); The import cost nothing. And by using the interface List<> then it is possible to change the actual type later to a different List<> implementation without worrying about code using methods only available in ArrayList<>. Reference: Effective Java 2nd Ed / Bloch Item 52. The question comes up frequently. SO examples: https://stackoverflow.com/questions/2279030/type-list-vs-type-arraylist-in-java https://stackoverflow.com/questions/9852831/polymorphism-why-use-list-list-new-arraylist-instead-of-arraylist-list-n https://stackoverflow.com/questions/18329311/reason-for-list-list-new-arraylist Arne