日期:2014-05-20  浏览次数:20720 次

一个基础问题大家帮忙
interface   Selector
{
boolean   end();
Object   current();
void   next();
}

public   class   Sequence   {
private   Object[]   objects;
private   int   next=0;
public   Sequence(int   size)
{
objects=new   Object[size];
}
public   void   add(Object   x)
{
if(next <objects.length)
{
objects[next++]=x;
}
}
private   class   SSelector   implements   Selector
{
private   int   i=0;
public   boolean   end()
{
return   i==objects.length;
}
public   Object   current()
{
return   objects[i];
}
public   void   next()
{
if(i <objects.length)
{
i++;
}
}
}
public   Selector   getSelector()
{
return   new   SSelector();
}

public   static   void   main(String[]   args)   {
Sequence   sequence=new   Sequence(10);
for(int   i=0;i <10;i++)
{
sequence.add(Integer.toString(i));
}
Selector   selector=sequence.getSelector();
while(!selector.end())
{
System.out.println(selector.current());
selector.next();

}
}
}
---------------------------------------
以上程序中下列代码都代表什么意识阿,都糊涂了帮个忙大家

private   Object[]   objects;

public   Selector   getSelector()
{
return   new   SSelector();
}


Selector   selector=sequence.getSelector();



------解决方案--------------------
就是获取一个内部类的实例 selector