> I don't think this is possible, but I figure it won't hurt to ask. I just
> might learn something new.
[quoted text clipped - 13 lines]
>
> I don't think this is possible, but is there a way to do it?
> Hal Vaughan schreef:
>> I don't think this is possible, but I figure it won't hurt to ask. I just
[quoted text clipped - 23 lines]
> anyway, so you might as well do the looping yourself, and do
> null-checking as well in the meantime.
Appart from utilizing multiple threads / CPUs to do the job faster is possible,
the main point is to remove unnecessary code, thereby making it shorter,
simpler, easyer to read and, in final consequence, getting rid of possible
hiding places for bugs.
Of course, implementing (& using) such a feature could be problematic. For
example, having an array containing instances of objects not all of which have a
.setActive(boolean) method. OK, an OperationNotSupportedException could be
thrown, which means one would have to catch it somewhere and those few lines of
code we were trying to get rid of, are here again. So I guess it's down to
generics: making sure, that all the entries are suitable.
<WishfullThinking>
Come to think of it, Mathematica has some powerful features related to such a
notion: http://documents.wolfram.com/mathematica/functions/Map (see also Map*,
Apply and Operate on the same page). I hear Java is eyeing closures for one its
future versions - maybe it could come with Map*, Apply and/or Operate at the
same time.
</WishfullThinking>
M.J. Dance - 08 Sep 2006 11:02 GMT
> Appart from utilizing multiple threads / CPUs to do the job faster is
> possible,
Make that _if_ possible.
Oliver Wong - 08 Sep 2006 16:29 GMT
>> Hal Vaughan schreef:
>>> I don't think this is possible, but I figure it won't hurt to ask. I
[quoted text clipped - 38 lines]
> guess it's down to generics: making sure, that all the entries are
> suitable.
Presumably, myObject has a type, and the operations you could perform on
myObject[] would be limited to those defined on the type of myObject.
List[] myLists = /*initialize somehow*/
myLists.toString(); /*Calls the method defined on the array*/
myLists[].toString(); /*Calls the method n times, on each element in
myList*/
myLists[].add(null); /*This works, as add(Object) is defined in the
interface List*/
myLists[].dance(); /*Compile time error, as the interface List doesn't
define a method "dance"*/
- Oliver
M.J. Dance - 11 Sep 2006 07:58 GMT
>> Of course, implementing (& using) such a feature could be problematic.
>> For example, having an array containing instances of objects not all
[quoted text clipped - 17 lines]
> myLists[].dance(); /*Compile time error, as the interface List doesn't
> define a method "dance"*/
Sure. But consider this.
List<Perform> list = ...;
Object[] array = list.toArray();
Although Perform could implement .dance(), one couldn't call array.dance(),
because Object (and thus Object[]) doesn't.
There are many such cases in Java API. Until generics, those seemed reasonable.
Now we have a strange mixture.