Java Iterator backed by a ResultSet

后端 未结 17 756
清歌不尽
清歌不尽 2020-12-13 06:51

I\'ve got a class that implements Iterator with a ResultSet as a data member. Essentially the class looks like this:

public class A implements Iterator{
            


        
17条回答
  •  忘掉有多难
    2020-12-13 07:21

    entities.next returns false if there are no more rows, so you could just get that return value and set a member variable to keep track of the status for hasNext().

    But to make that work you would also have to have some sort of init method that reads the first entity and caches it in the class. Then when calling next you would need to return the previously cached value and cache the next value, etc...

提交回复
热议问题