N9I - 3/17/2010

Written on Sun, 11 Apr 2010 17:41:05 +0000 - Last updated on Sun, 11 Apr 2010 17:47:24 +0000A journal entry in the development of the N9I programming language, dated March 17, 2010

Casting via Assignment to Existing Objects

In the entry N9I - 2/12/2010 casting annotations "to" and "from" were discussed, which allow the programmer to transparently juggle objects between types. However, the from annotation in that example was applied to a static method. That example described creating a new object "from" an existing one. This note explains how to add the "from" annotation to non-static methods, such that assigning a walue to the object's variable does not overwrite the existing object reference. [from String] public void fromStr(String str) ... The only limitation is that this value cannot be null. Setting a variable to null always resets it. Thus doing something like var = null && var = value; bypasses the cast method entirely, if need be.