n**********2 发帖数: 214 | 1 很简单,呵呵。写一个函数的具体实现。
/**
* Given a list of objects, returns the last object in the list that is an
instance of type Foo.
* @param stuff the list of objects
* @return an object of type Foo
* @throws NoSuchFooException if there is no Foo in the list
*/
Foo getLastFoo(List stuff) throws NoSuchFooException; |
n**********2 发帖数: 214 | 2 答案:
Foo getLastFoo(List stuff) throws NoSuchFooException {
for (int i=stuff.size()-1; i>=0; i--) {
if (stuff.get(i) instanceof Foo) {
return (Foo) stuff.get(i);
}
}
throw new NoSuchFooException();
}
【在 n**********2 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 很简单,呵呵。写一个函数的具体实现。 : /** : * Given a list of objects, returns the last object in the list that is an : instance of type Foo. : * @param stuff the list of objects : * @return an object of type Foo : * @throws NoSuchFooException if there is no Foo in the list : */ : Foo getLastFoo(List stuff) throws NoSuchFooException;
|
B********4 发帖数: 7156 | 3 先谢谢了。
面试就一个题目?还是说coding方面就这一个? |