Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: What's the best way to make a cross string set? Date: Mon, 31 Jul 2017 12:01:39 -0400 Organization: A noiseless patient Spider Lines: 42 Message-ID: References: <6f9ff338-1944-4b64-83b8-4a921ce57a89@googlegroups.com> <1c3dafe0-c2ed-4ea1-9c06-b069f20c16ea@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 31 Jul 2017 15:57:38 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="48e88d39453d72bccceb1a6200c9ae23"; logging-data="29063"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+d4kbC+VqiRn79OikPDMM0" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 In-Reply-To: <1c3dafe0-c2ed-4ea1-9c06-b069f20c16ea@googlegroups.com> Content-Language: en-US Cancel-Lock: sha1:MgveFzhDhCIQuWArnLd6EB/pqNg= Xref: csiph.com comp.lang.java.programmer:37034 On 7/31/2017 8:24 AM, Eric Douglas wrote: > On Friday, July 28, 2017 at 5:21:09 PM UTC-4, Eric Sosman wrote: >> ArrayList list1 = new ArrayList() >> should have been something like >> List> list1 = new ArrayList<>(); >> or >> List> list1 = new ArrayList<>(); >> or even >> List> list1 = new ArrayList<>(); >> and >> ArrayList list2 = new ArrayList() >> should have been >> List list2 = new ArrayList<>(); >> or maybe >> Collection list2 = new ArrayList<>(); >> ... and, of course, other variations are possible. >> > > You're saying declaring a variable as a List is more efficient even if you know it's going to be instantiated as ArrayList? No, I did not say that, nor anything remotely like it. I won't re-hash the pros and cons of declaring interface types vs. concrete types, as they are probably covered in the instructional materials you skimmed too hastily. (I've mentioned before that you exhibit a strange combination of sophistication and ignorance, and I surmise that your extensive experience with other programming languages may have led you to short-change your Java studies and jump right in -- and find yourself in over your head.) What I *did* say is that it is *better* (not "more efficient") to declare List (or ArrayList, if you prefer) than raw ArrayList. If you do not know why, go back to the books. > 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. The pros and cons of interface vs. concrete declaration are, as I said, well-known to anyone who has given Java even a moderate degree of attention. Go thou, and so do. -- esosman@comcast-dot-net.invalid Twelve hundred sixty-nine days to go.