[OT] Just a thought...
[OT] Just a thought...
- Subject: [OT] Just a thought...
- From: Florijan Stamenkovic <email@hidden>
- Date: Mon, 3 Mar 2008 11:17:36 -0400
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:
This email sent to email@hidden