views:

23

answers:

1

While I was trying to build a Number subclass in AS3 I noticed I cannot extend the Number/int/etc. classes --- they are final.

The next best thing was casting. Still, I also don't think this is possible but since I've been asking myself this for a while I said I'd ask here to find out.

Can you create custom casting for a class you created? For example:

var myObject:MyClass = MyClass('string');

And somewhere in MyClass to be able to set the behavior for converting a String object into it.

If not Flash AS3, than what language allows you to do this? I find it a bit fascinating.

+2  A: 

C# allows user-defined cast operators using explicit.

http://msdn.microsoft.com/en-us/library/xhbhezf4%28VS.71%29.aspx

grossvogel
Nice, `implicit` casting is even cooler! C# looks pretty cool from this point of view. :)
treznik
I like---more examples! :) Does anyone know if you can do this in Java?
treznik