Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: array of HashSet<> Date: Sat, 27 Feb 2016 11:41:18 +0100 Lines: 45 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net J7VSBRnqjrSWRVx2QTJxSw4CciaUIhg++CT36uGpscsQ3+b7g= Cancel-Lock: sha1:ShmsTa63rsQfjpwhXnH7Jdp/LQo= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:33888 On 27.02.2016 01:12, Roedy Green wrote: > I take it is impossible to write a valid Java program containing an > array of HashSet<> s. > > Any ideas for a work around? I am not sure what you are asking. package cljp; import java.util.ArrayList; import java.util.HashSet; public final class ArrayOfHashSet { public static HashSet validProgram() { @SuppressWarnings("unchecked") final HashSet[] arrayOfHashSets = (HashSet[]) new HashSet[10]; for (int i = 0; i < arrayOfHashSets.length; ++i) { arrayOfHashSets[i] = new HashSet<>(); } return arrayOfHashSets[1]; } public static HashSet workaround() { final ArrayList> arrayOfHashSets = new ArrayList<>(); for (int i = 0; i < 10; ++i) { arrayOfHashSets.add(new HashSet<>()); } return arrayOfHashSets.get(1); } } Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/