静态内部类(
InnerClass)意味着
<wbr style="line-height:25px"><span style="color:#003366; line-height:25px">1创建一个static内部类的对象,不需要一个外部类对象<br style="line-height:25px"> 2不能从一个static内部类的一个对象访问一个外部类对象</span><wbr style="line-height:25px"><br style="line-height:25px"><span style="line-height:25px">示例1</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">publicclass</span><span style="color:#3366ff; line-height:25px"></span><span style="color:#ff6600; line-height:25px">Filter</span><span style="color:#3366ff; line-height:25px">{<br style="line-height:25px"> Vectorcriteria=newVector();<br style="line-height:25px"></span><span style="color:#993300; line-height:25px">public</span><span style="color:#3366ff; line-height:25px">addCriterion(Criterionc){<br style="line-height:25px"> criteria.addElement(c);<br style="line-height:25px"> }<br style="line-height:25px"></span><span style="color:#993300; line-height:25px">publicboolean</span><span style="color:#3366ff; line-height:25px">isTrue(Recordrec){<br style="line-height:25px"> for(Enumeratione=criteria.elements();<br style="line-height:25px"> e.hasMoreElements();){<br style="line-height:25px"> if(!((Criterion)e.nextElement()).isTrue(rec))<br style="line-height:25px"> returnfalse;<br style="line-height:25px"> }<br style="line-height:25px"> returntrue;<br style="line-height:25px"> }<br style="line-height:25px"></span><span style="color:#993300; line-height:25px">publicstaticclass</span><span style="color:#3366ff; line-height:25px">Criterion{<br style="line-height:25px"> StringcolName,colValue;<br style="line-height:25px"></span><span style="color:#993300; line-height:25px">public</span><span style="color:#3366ff; line-height:25px">Criterion(Stirngname,Stringval){<br style="line-height:25px"> colName=name;colValue=val;<br style="line-height:25px"> }<br style="line-height:25px"></span><span style="color:#993300; line-height:25px">publicboolean</span><span style="color:#3366ff; line-height:25px">isTrue(Recordrec){<br style="line-height:25px"> Stringdata=rec.getData(colName);<br style="line-height:25px"></span><span style="color:#993300; line-height:25px">if</span><span style="color:#3366ff; line-height:25px">(data.equals(colValue))returntrue;<br style="line-height:25px"> returnfalse;<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"> }</span><br style="line-height:25px"> Andwhenyouwanttouseit:<br style="line-height:25px"> Java代码<br style="line-height:25px"><br style="line-height:25px"><span style="color:#3366ff; line-height:25px">1.Filterf=newFilter();<br style="line-height:25px"> 2.f.addCriterion(newFilter.Criterion("SYMBOL","SUNW"));<br style="line-height:25px"> 3.f.addCriterion(newFilter.Criterion("SIDE","BUY"));<br style="line-height:25px"> 4......<br style="line-height:25px"> 5.if(f.isTrue(someRec))//dosomething.....</span></wbr></wbr>
<wbr style="line-height:25px"><span style="color:#003366; line-height:25px">1创建一个static内部类的对象,不需要一个外部类对象<br style="line-height:25px"> 2不能从一个static内部类的一个对象访问一个外部类对象</span><wbr style="line-height:25px"><br style="line-height:25px"><span style="line-height:25px">示例1</span><br style="line-height:25px"><span style="color:#993300; line-height:25px">publicclass</span><span style="color:#3366ff; line-height:25px"></span><span style="color:#ff6600; line-height:25px">Filter</span><span style="color:#3366ff; line-height:25px">{<br style="line-height:25px"> Vectorcriteria=newVector();<br style="line-height:25px"></span><span style="color:#993300; line-height:25px">public</span><span style="color:#3366ff; line-height:25px">addCriterion(Criterionc){<br style="line-height:25px"> criteria.addElement(c);<br style="line-height:25px"> }<br style="line-height:25px"></span><span style="color:#993300; line-height:25px">publicboolean</span><span style="color:#3366ff; line-height:25px">isTrue(Recordrec){<br style="line-height:25px"> for(Enumeratione=criteria.elements();<br style="line-height:25px"> e.hasMoreElements();){<br style="line-height:25px"> if(!((Criterion)e.nextElement()).isTrue(rec))<br style="line-height:25px"> returnfalse;<br style="line-height:25px"> }<br style="line-height:25px"> returntrue;<br style="line-height:25px"> }<br style="line-height:25px"></span><span style="color:#993300; line-height:25px">publicstaticclass</span><span style="color:#3366ff; line-height:25px">Criterion{<br style="line-height:25px"> StringcolName,colValue;<br style="line-height:25px"></span><span style="color:#993300; line-height:25px">public</span><span style="color:#3366ff; line-height:25px">Criterion(Stirngname,Stringval){<br style="line-height:25px"> colName=name;colValue=val;<br style="line-height:25px"> }<br style="line-height:25px"></span><span style="color:#993300; line-height:25px">publicboolean</span><span style="color:#3366ff; line-height:25px">isTrue(Recordrec){<br style="line-height:25px"> Stringdata=rec.getData(colName);<br style="line-height:25px"></span><span style="color:#993300; line-height:25px">if</span><span style="color:#3366ff; line-height:25px">(data.equals(colValue))returntrue;<br style="line-height:25px"> returnfalse;<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"> }</span><br style="line-height:25px"> Andwhenyouwanttouseit:<br style="line-height:25px"> Java代码<br style="line-height:25px"><br style="line-height:25px"><span style="color:#3366ff; line-height:25px">1.Filterf=newFilter();<br style="line-height:25px"> 2.f.addCriterion(newFilter.Criterion("SYMBOL","SUNW"));<br style="line-height:25px"> 3.f.addCriterion(newFilter.Criterion("SIDE","BUY"));<br style="line-height:25px"> 4......<br style="line-height:25px"> 5.if(f.isTrue(someRec))//dosomething.....</span></wbr></wbr>