静态内部类(Inner Class)

静态内部类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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值