From d1b997b9ff39ac139940fed1a40d242e1d0f41b3 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Fri, 17 Mar 2006 01:19:15 +0000 Subject: [PATCH] Another note. There are 3 ways to cast and all of them suck in one way or another! git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3956 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/README.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/as/com/threerings/README.txt b/src/as/com/threerings/README.txt index 3fa8715f6..99d866c63 100644 --- a/src/as/com/threerings/README.txt +++ b/src/as/com/threerings/README.txt @@ -195,6 +195,25 @@ ActionScript var o1 :String = someObject; // checked at runtime, throws TypeError if failure + Also, when the compiler is in strict mode it flags this code, so + we can't win. + + I will sum up in a table: + + * cast using "obj as Type" + + helps compile-time type checking + - turns non-castable objects into null rather than generating an exception + * casting using "Type(obj)" + + helps compile-time type checking + - will coerce primitive types between each other, the most annoying + problem being: + var o1 :Object = null; + var s1 :String = String(o1); + assert(s1 === "null"); + * implicit casting ("var s :String = o") + + it will generate a proper TypeError at runtime + - no compile-time checking, strict compiler generates an error (!!!) + - Pitfall! This is perfectly legal: var b :int = 3;