Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[OT] Just a thought...



Hi all,

Would it not be cool if Java supported streamlined class conversion? Something like this could be declared in the Object class, to be overridden in subclasses:

public Class[] convertableTo(){ return new Class[0]}

public <T> T convertTo(Class<T> clazz) throws CanNotConvertException { return null; }

This could then be used by the compiler, to determine convertibility (well, as best as possible) at compile time... We could write stuff like:

byte[] data = getSomeNSDataObject();
for(int i = 0 ; i < someArray ; i++) // here an array converts to an int according to it's size
try{
int userInput = getUserInputString();
}catch(CanNotConvertException ec){...}


And this would be cool because then conversions (which we all do a lot in our code) could be written implicitly, without the need to call API specific methods like:

byte[] data = getSomeNSDataObject().bytes();

Well, I am sure there would be drawbacks to the implementation, or better to say peculiarities :) , like with autoboxing and, ahem, generics, but I can't think of any major problems, of the top of my head... Well, there'd be more possibilities for screw ups, but Java is generally easy going (compared to the C family at least), so a bit more care would not kill anyone.

...
F

p.s. - I'm just frustrated because I'm maintaining a ValueConverter class for JBND, and it's annoying...
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/email@hidden


This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.