Re: Object or <T> parameters
[email protected] Tue, 24 Feb 2004 19:12:41 -0600
| Newsgroups | gmane.comp.lang.nice.general |
|---|---|
| Message-ID | <[email protected]> |
Quoting Bryn Keller <[email protected]>: >I think it's reasonable. It might be nice to have it print name, type >information, and so on. Even if it doesn't, I don't see what the issue >is. If it's first class, you ought to be able to inspect it, IMHO. I agree, it might be a useful feature. But, is the current behavior useful? I personally don't think it is. It seems likely that whenever we write: x + f + y when f is a function, we really mean: x + f() + y. given that toString(t) doesn't do what you describe above. > [email protected] wrote: > >For example, why should the following program typcheck? What does > >newInstance(getClass(() => true)) mean?: > > void main(String [] args) { > > let a = new Date(); > > let b = newInstance(getClass(a)); > > let c = () => true; > > let d = newInstance(getClass(a)); // ??? > > } > > > > > Did you mean "let d = newInstance(getClass(c))"? I would think it would > create a new method. This would fail at runtime I imagine, since methods > probably wouldn't have no-arg constructors. Yes, that is what I meant. What does getClass() mean for methods? > >That is, it seems that getClass should have type: > > <Object T> Class<T> getClass(T); > >Where <Object T> means "not a function," possibly also "not a primitive > type." > > > Helpful in that case, but not in this: > > <T,U> List<U> callEach(List<T->U> funcs, T arg) { > List<U> result = new ArrayList(); > for(T->U func : funcs) { > println("Calling " + func); > result.add(func(arg)); > } > } I agree. And, even if you implement my suggestion then this would work just fine, unchanged. I am merely saying it should be possible to say things like: <Object T> Class<T> getClass(T); Which means that T must be an instance of an object type (interface, class, enum). > >It is basically the same motivation that you had for delayed<T> in the > >expression-local variables thread, namely catching likely typos during > typechecking. > > > > > A worthwhile goal, but I'm not convinced that benefits outweigh the costs. Fair enough. This is not a huge deal to me. I think it is something to consider when implementing features based on the block call syntax(es). - Brian ------------------------------------------------------- SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now! http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click