没用过接口,试着写了一个,但是不知道到底该怎么调用。
ICardList.javapublic interface ICardList
{
    boolean rollList(String cardId);
}
Factory.javapublic class Factory
{
    public static ICardList rollList( )
    {
        return new CardList();
    }
}
CardList.javapublic class CardList implements ICardList
{
    public boolean rollList( String cardId )
    {
        boolean whether = false;        return whether;
    }
}我现在在一个 Start.java 类中的 aaa方法中 想调用 rollList 方法该怎么写呢?谢谢public class Start
{
    public void aaa()
    {    }
}

解决方案 »

  1.   

    class Start{
      static ICardList a = new CardList();
        public void aaa(){
              a.rollList("a");
        }
     
    }
    这样就行了!
      

  2.   

    String cardId="zx";
    boolean bol;
    CardList zx = new CardList();
    bol=zx.rollList(cardId);
      

  3.   

    既然要用工厂模式
    public class Start
    {
        public void aaa()
        {
            //Factory f=new Factory();
            ICardList icl=Factory.rollList();//f.rollList();
            icl.rollList("haha");
        }
        public static void main(String[] args)
        {
            Start s=new Start();
            s.aaa();
        }
    }
      

  4.   

    public class Start
    {
         public void aaa()
         {
              Factory.rollList().rollList("woo");
         }
    }