Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7165
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: enhance an array's static type by a lower length-bound. |
| Date | 2011-08-17 20:42 +0200 |
| Message-ID | <9b2gcfFcg7U1@mid.individual.net> (permalink) |
| References | <slrnj4nm33.6gl.avl@gamma.logic.tuwien.ac.at> |
On 17.08.2011 17:04, Andreas Leitgeb wrote: > The point of the idea is, that array variables would be added a static > bit of information, namely a lower bound (0 by default) for the length > of an array that can legally be stored in that variable. > I believe such a change would be source-compatible, but might require > some severe changes at the bytecode/class-file-format level, to allow > to specify such a lower bound in a type signature. Such a change should > be possible in a way, that old class-files can still be used. e.g.: > get9th:(]10I)I (currently without bounds: get9th:([I)I ) > > Methods could overload others just for different length-bounds. > The one with the largest provably satisfyable length-bound would be > chosen among those with otherwise matching signature. Not sure whether this would work - especially since binding of the signature occurs at compile time while you might only learn the real length of a parameter at runtime. Also there is probably a whole lot of issues with java.lang.reflect. > Another one could be, that ArrayIndexOutOfBoundsExceptions are > not currently perceived as a problem that could be alleviated > by static checks, anyway. I think this is closer to the real reason why this is probably not such a good idea. What you propose would be useful only if the added property of arrays would allow for *compile time* checking - because Java has runtime checks already. For compile time checks to be reasonable you would need to forbid int[] a1 = expr; int[10] a2 = a1; because depending on the complexity of expr it might not be possible for the compiler to determine the guaranteed min length of a1. And finally the question: how often do you know the array length in advance? How useful is this in practice? I have the feeling that people would use this as a lazy shortcut for defining a class with n integer fields. And then how does the usefulness weight against the cost of realizing this? I think your intuition (that we won't see this) was pretty good already. :-) 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
enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-17 15:04 +0000
Re: enhance an array's static type by a lower length-bound. Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-17 12:34 -0500
Re: enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-18 13:14 +0000
Re: enhance an array's static type by a lower length-bound. Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-18 10:30 -0500
Re: enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-18 18:12 +0000
Re: enhance an array's static type by a lower length-bound. Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-18 20:59 -0500
Re: enhance an array's static type by a lower length-bound. Robert Klemme <shortcutter@googlemail.com> - 2011-08-17 20:42 +0200
Re: enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-18 21:44 +0000
Re: enhance an array's static type by a lower length-bound. Robert Klemme <shortcutter@googlemail.com> - 2011-08-19 13:24 +0200
Re: enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-20 17:20 +0000
Re: enhance an array's static type by a lower length-bound. Roedy Green <see_website@mindprod.com.invalid> - 2011-08-17 22:11 -0700
Re: enhance an array's static type by a lower length-bound. Lew <lewbloch@gmail.com> - 2011-08-17 23:17 -0700
Re: enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-18 10:41 +0000
Re: enhance an array's static type by a lower length-bound. Patricia Shanahan <pats@acm.org> - 2011-08-18 06:34 -0700
Re: enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-18 18:08 +0000
Re: enhance an array's static type by a lower length-bound. Roedy Green <see_website@mindprod.com.invalid> - 2011-08-18 17:53 -0700
Re: enhance an array's static type by a lower length-bound. Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-20 17:31 +0000
Re: enhance an array's static type by a lower length-bound. Lew <lewbloch@gmail.com> - 2011-08-20 10:50 -0700
Re: enhance an array's static type by a lower length-bound. Robert Klemme <shortcutter@googlemail.com> - 2011-08-21 10:47 +0200
Re: enhance an array's static type by a lower length-bound. Michal Kleczek <kleku@poczta.onet.pl> - 2011-08-21 20:27 +0200
csiph-web