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


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

Re: array of HashSet<>

From Andreas Leitgeb <avl@logic.at>
Newsgroups comp.lang.java.programmer
Subject Re: array of HashSet<>
Date 2016-02-29 13:19 +0000
Organization A noiseless patient Spider
Message-ID <slrnnd8hh8.456.avl@login.logic.tuwien.ac.at> (permalink)
References (2 earlier) <naut84$15fq$1@gioia.aioe.org> <nauu45$fbe$1@dont-email.me> <navbsc$me$1@gioia.aioe.org> <nave1c$gl2$1@dont-email.me> <navtov$200$1@news.albasani.net>

Show all headers | View raw


Sebastian <news@seyweiler.dyndns.org> wrote:
> So I'd say Roedy is right: Clearly it is the intent of the Java compiler 
> to forbid creation of generic arrays the component type of which is a 
> parameterized type. Which includes HashSet<Long>. Ironically, the reason 
> why it wants to forbid that is also the reason why it must fail in the 
> attempt...
> I guess reified generic types are high on everybody's wish list.

The problem with non-reifiable arrays is, that arrays can be casted
to arrays of superclass types and this thwarts all control over what
exactly can get written into an array.

I think there is a loophole that some future version of Java could
in principle use to further avoid reifiable generics...

A *future* version of Java could allow non-reifiable arrays,
but would need to warn against their casting to other array-
types, like:
  Set<Long>[] arrOfSets = new Set<Long>[1]; // fine
  arrOfSets[0] = new HashSet<Long>();
  for( HashSet<Long> item : arrOfSets ) { ... } // fine, too
  // but:
  Object[] arrOfObj = arrOfSets; // <-- some generics-warning here!

I think, as long as such an array would be referenced only by its exact
type, then there would be no way of misuse. It's only when an array is
casted, that all generics-inferred guarantees are necessarily off.

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