当前位置: 代码迷 >> J2SE >> 一个基础有关问题大家帮忙
  详细解决方案

一个基础有关问题大家帮忙

热度:69   发布时间:2016-04-24 14:39:46.0
一个基础问题大家帮忙
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
  相关解决方案