title: How to return an object from enum in Java?
body: <p>I am have a number of classes which implement same interface. The objects for all those classes have to be instantiated in a main class. I am trying to do it in a manner with which this thing could be done in an elegant manner (I thought through enum). Example code :-</p>
  
  <pre><code>public interface Intr {
  //some methods
  }
  
  public class C1 implements Intr {
  // some implementations
  }
  
  public class C2 implements Intr {
  // some implementations
  }
  
  ...
  
  public class Ck implements Intr {
  // some implementations
  }
  
  
  public class MainClass {
  
  enum ModulesEnum {
  //Some code here to return objects of C1 to Ck
   FIRST {return new C1()},
   SECOND {return new C2()},
   ...
   KTH  {return new Ck()};
  }
  
  }
  </code></pre>
  
  <p>Now in the above example for some elegant way with which I can get instances of new objects of Class C1 to Ck. Or any other better mechanism instead of enum will also be appreciated.</p>