ndw’s avatarndw’s Twitter Archive—№ 32,599

  1. What is the contract for a (Java) Iterator? If I know the iterator will contain three items, can I call next() three times or am I obligated to call hasNext()? (Conversely, is an implementation in violation of the contract if it updates mutable state on hasNext()?)