Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
haXe 2 Beginner's Guide

You're reading from  haXe 2 Beginner's Guide

Product type Book
Published in Jul 2011
Publisher
ISBN-13 9781849512565
Pages 288 pages
Edition 1st Edition
Languages

Table of Contents (21) Chapters

haxe 2
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Getting to know haXe 2. Basic Syntax and Branching 3. Being Cross-platform with haXe 4. Understanding Types 5. The Dynamic Type and Properties 6. Using and Writing Interfaces, Typedefs, and Enums 7. Communication Between haXe Programs 8. Accessing Databases 9. Templating 10. Interfacing with the Target Platform 11. A Dynamic Website Using JavaScript 12. Creating a Game with haXe and Flash Pop Quiz Answers Index

Static typing


In haXe, once a variable has been declared and its type is known, it is not possible to assign a value of another type to it. Note however that the compiler allows you to redeclare a variable with the same name and another type. So, the following code compiles:

class Main
{
   public static function main()
   {
      var e : String;
      e = "String";
      var e : Int;
      e = 12;
   }
}

However, although this code compiles, you should not be doing this because it might be confusing to other developers or even to you as well, if you have to read your code several days later.

Therefore, to keep things simple, once a variable is typed, its type cannot be changed, and only values of this type can be assigned to it. So, the following wouldn't work:

class Main
{
   public static function main()
   {
      var e : String;
      e = "Test";
      e = 12;
   }
}

This is because 12 is of type Int and not of type String.

Also, note that if you try to read from a variable without having...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime}