Book Image

haXe 2 Beginner's Guide

5 (1)
Book Image

haXe 2 Beginner's Guide

5 (1)

Overview of this book

Table of Contents (21 chapters)
haxe 2
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Our main function


Now we will create a simple main function in order to test whether everything works as expected.

In this function, we will create our Fridge, create two items, and add them in the fridge. Then we will iterate over our fridge:

class FridgeManager
{
   private static var fridge : fridgeManager.Fridge;
   
   public static function main(): Void
   {
      fridge = new fridgeManager.Fridge();
      
      var myDrink = new fridgeManager.Drink();
      myDrink.name = "Benjamin's drink";
      
      var myFood = new fridgeManager.Food();
      myFood.name = "Benjamin's food";
      
      fridge.addItem(myDrink);
      fridge.addItem(myFood);
      
      //Let's display what's inside the fridge:
      for(stored in fridge)
      {
         trace(stored.name);
      }
   }
}

Pop quiz – Typedef, interfaces, and Enums

  1. Is it possible for the compiler to be able to do type inference inside interfaces?

    1. Yes, it is possible

    2. Yes, but only if the interface is implemented in a class

    3. No, it is...