Gosu Basics for Null

740 views
Skip to first unread message

chiasso...@gmail.com

unread,
Mar 10, 2015, 10:01:02 AM3/10/15
to gosu...@googlegroups.com
Hello.  in Gosu, is Null a legal value for any variable?

Alan Keefer

unread,
Mar 10, 2015, 12:03:46 PM3/10/15
to gosu...@googlegroups.com
Gosu works like Java in this respect:  null is a legal value for any Object type, but not for primitive types.

-Alan

On Tue, Mar 10, 2015 at 7:01 AM, <chiasso...@gmail.com> wrote:
Hello.  in Gosu, is Null a legal value for any variable?

--
You received this message because you are subscribed to the Google Groups "gosu-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gosu-lang+...@googlegroups.com.
To post to this group, send email to gosu...@googlegroups.com.
Visit this group at http://groups.google.com/group/gosu-lang.
For more options, visit https://groups.google.com/d/optout.

Wojciech Sadlik

unread,
Oct 26, 2015, 6:19:04 AM10/26/15
to gosu-lang
Not quite Alan. It's unlike in Java. Look for example:
var a : int = null
print("Null value equals: " + a)
var sum : int = a + 3
print("Null + 3 equals: " + sum)
Null value equals: 0
Null + 3 equals: 3
So as you can see it's possible to assign null to primitives and in this case convert it to zero.

Alan Keefer

unread,
Oct 26, 2015, 11:53:56 AM10/26/15
to gosu...@googlegroups.com
What version of Gosu are you using there?  Null was a legal value for primitives in Gosu in much older versions, back when Gosu was executed off of the parsed AST rather than compiled down into Java bytecode.  Once we moved to Java bytecode (probably 5 years ago?), we had to tighten things up to obey the Java semantics, so null is no longer a valid value for an int in Gosu.

-Alan

Luca Boasso

unread,
Oct 26, 2015, 11:55:05 AM10/26/15
to gosu...@googlegroups.com
Yep, that code is illegal in the current version of Gosu.

Reply all
Reply to author
Forward
0 new messages