Thursday, January 20, 2011

Note to self: Actionscript Strings are not Java Strings!

var s1: String = "gerard";
var s2: String = "gerard";
Alert.show( (s1 == s2).toString() );


In Actionscript the above displays true. Apparently there is a built in string comparison operator in Flash that compares the content, instead of the object references themselves.



This is actually intuitive. If I give anyone on the street 2 identical Bibles, and ask them "are they the same?", they would say "yes". Java devs will tell you their content is the same, but they are in fact 2 different instances of the books. 


I wonder what else is Java programming doing to my brain...

No comments:

Post a Comment