/* ============================================================================ * File: Main.java * ---------------------------------------------------------------------------- * * This file is part of the Microsoft Supplemental UI Library for Visual J# .NET * Code Samples. * * Copyright (C) 2003 Microsoft Corporation. All rights reserved. * * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, * WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. * ============================================================================ */ package RecursionDemo; // Reflection APIs to get classes implementing RecursiveFunction import System.Reflection.*; import System.Type; // ArrayList import java.util.ArrayList; /** * This is the main class. */ public class Main { /** * Main function */ public static void main(String[] args) { /* * This function uses reflection to determine the classes implementing * RecursiveFunction interface. If you do not want to use reflection, * uncomment the line below and comment rest of this function. * Ensure that the line below includes all the recursive function. */ // new StackJFrame(new RecursiveFunction[] {new Factorial(), new SumN()}); ArrayList list = new ArrayList(10); Type[] types = Assembly.GetExecutingAssembly().GetTypes(); for (int i = 0; i < types.length; i++) { if (types[i].GetInterface("RecursiveFunction") != null) list.add(types[i]); } RecursiveFunction[] funcs = new RecursiveFunction[list.size()]; for (int i = 0; i < list.size(); i++) { funcs[i] = (RecursiveFunction)((Type)list.get(i)).GetConstructor(new Type[0]).Invoke(null); } new StackJFrame(funcs); } }