unknown depthSearch(Tree tree, unknown find);
unknown entry = "This is a string";
?unknown first = null;
unknown[] list1 = new unknown[50];
var list2 = new ArrayList<unknown>();
int len = entry.length(); // works because entry currently refers to a String and because
// String.length() returns an int
file = new File(entry); // works because File has a Sring constructor, and without typecasting
int width = entry.width(); // would compile, but fail at runtime
Set<int> set = entry.charAt(0); // seems silly, but would compile, then fail at runtime
unknown found = list2[15];
if (found instanceof Number) {
/* Compiler knows 'found' is a Number here and can take advantage of that */
}
unknown `.`(row@Results, String column);you can already write:
<T> T `.`(row@Results, String column);which says: the return type is T, for whatever value of T you choose (since T does not appear in the parameter list). This is already used in the standard library for serialization/deserialization without casts. You can also look at this forum thread about reflexion support. This does not allow to have a local variable of any type, though, because T must be declared in a method type. But I believe this already covers many interesting cases. -- DanielBonniot - 25 Oct 2003
`.` is valid. However, you would not be able to call it using the e1.e2 syntax, so that's not yet what you want (in the other discussion). My point here was about typing.
2) You're right, using <T> for unknown types does not carry on to arrays. What you can do currently is use Object for that purpose. You can convert any value to Object by using the method object(...). On the way back, you would use a cast or instanceof.
3) Basic support exists, using Object as described above. One could do better, by not requiring the use of object(...) (that is, make Object the top type). This should not be very difficult.
If you want to allow any operation on Object (or unknown) to succeed, and discover the operation at runtime, that would more work. Although maybe you could just rewrite f(e1, ..., eN) where at least one of e1...eN has the unknown type into dynamic_call("f", e1, ..., eN), and implement dynamic_call as a library function that uses reflexion and the class of its arguments to find what method to call. Is this what you are driving to?
It's interesting, although my bias is usually more towards static solutions. I'm not sure if you are awre that Nice is already quite clever about instanceof, so you don't need casts in addition:
Object f = operationReturningAnything();
if (f instanceof String) {
// f has type String here, no cast required.
int len = f.length(); // String operation, resolved at compile time.
}
This removes about half of the boilerplate needed in Java when using arbitrary types. If the removal of object(...) mentioned above was implemented, would not this provide quite a good support already, without loosing any type safety?
-- DanielBonniot
| Topic UnknownType . { Edit | Attach | Ref-By | Printable | Diffs | r1.4 | > | r1.3 | > | r1.2 | More } |
|
Revision r1.4 - 12 Nov 2003 - 14:01 GMT - DanielBonniot Parents: WebHome > FeatureProposals |
Copyright © 1999-2003 by the contributing authors.
All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding TWiki? Send feedback. |