Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33888

Re: array of HashSet<>

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: array of HashSet<>
Date 2016-02-27 11:41 +0100
Message-ID <djdcqfF4hjmU1@mid.individual.net> (permalink)
References <tbq1dbl7do4o9bdqo98prrmhe8tm4g6710@4ax.com>

Show all headers | View raw


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 <T> HashSet<T> validProgram() {
         @SuppressWarnings("unchecked")
         final HashSet<T>[] arrayOfHashSets = (HashSet<T>[]) new 
HashSet<?>[10];

         for (int i = 0; i < arrayOfHashSets.length; ++i) {
             arrayOfHashSets[i] = new HashSet<>();
         }

         return arrayOfHashSets[1];
     }

     public static <T> HashSet<T> workaround() {
         final ArrayList<HashSet<T>> 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/

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

array of HashSet<> Roedy Green <see_website@mindprod.com.invalid> - 2016-02-26 16:12 -0800
  Re: array of HashSet<> Arne Vajhøj <arne@vajhoej.dk> - 2016-02-26 20:01 -0500
    Re: array of HashSet<> Arne Vajhøj <arne@vajhoej.dk> - 2016-02-27 10:05 -0500
  Re: array of HashSet<> Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2016-02-26 21:13 -0800
  Re: array of HashSet<> Robert Klemme <shortcutter@googlemail.com> - 2016-02-27 11:41 +0100
  Re: array of HashSet<> Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2016-02-27 11:54 -0800
    Re: array of HashSet<> Lew <lewbloch@gmail.com> - 2016-02-27 15:16 -0800
      Re: array of HashSet<> Lew <lewbloch@gmail.com> - 2016-02-27 15:18 -0800
  Re: array of HashSet<> Roedy Green <see_website@mindprod.com.invalid> - 2016-02-27 23:44 -0800
    Re: array of HashSet<> Lew <lewbloch@gmail.com> - 2016-02-28 01:52 -0800
    Re: array of HashSet<> Arne Vajhøj <arne@vajhoej.dk> - 2016-02-28 08:38 -0500
      Re: array of HashSet<> Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-28 08:56 -0500
        Re: array of HashSet<> Arne Vajhøj <arne@vajhoej.dk> - 2016-02-28 12:47 -0500
          Re: array of HashSet<> Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-28 13:27 -0500
            Re: array of HashSet<> Sebastian <news@seyweiler.dyndns.org> - 2016-02-28 23:53 +0100
              Re: array of HashSet<> Arne Vajhøj <arne@vajhoej.dk> - 2016-02-28 21:16 -0500
                Re: array of HashSet<> Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2016-02-28 23:36 -0800
                Re: array of HashSet<> Roedy Green <inquiry@mindprod.com> - 2016-06-08 20:08 -0700
              Re: array of HashSet<> Andreas Leitgeb <avl@logic.at> - 2016-02-29 13:19 +0000
                Re: array of HashSet<> Andreas Leitgeb <avl@logic.at> - 2016-02-29 13:27 +0000
  Re: array of HashSet<> Daniel Pitts <usenet@coloraura.com> - 2016-03-06 13:59 -0800
    Re: array of HashSet<> Roedy Green <inquiry@mindprod.com> - 2016-06-08 20:10 -0700
      Re: array of HashSet<> Lew <lewbloch@gmail.com> - 2016-06-10 12:25 -0700
        Re: array of HashSet<> Daniel Pitts <usenet@coloraura.com> - 2016-06-11 12:30 -0700
        Re: array of HashSet<> Roedy Green <inquiry@mindprod.com> - 2016-06-12 02:31 -0700

csiph-web