Kenneth A. Kousen, Ph.D. (assorted certs),
President, Kousen IT, Inc, http://www.kousenit.com
Because you are not exposing a mutable reference type field to the outside world, that looks considerably better than simply returning the Collection<Address>. I think you will get a new Stream object every time that method is called.Narendran Sridharan wrote:. . . one use case may be as below. . . .
It's windowed and everything
That's a pleasureNarendran Sridharan wrote:Thank you Kousen & Campbell.
Agree. But the mechanism is different. You iterate a Collection directly by creating an Iterator for it. You create a Stream with the stream method (or otherwise) and the Stream uses the collection's Iterator behind the scenes, so look on the Stream the way you look on Iterators rather than the way you look on the Collection itself. As you know, you have to create Iterators anew every time you want to use them; the same applies to Streams.
1. It is better to create new Stream all the time. Because stream can be traveled only once unlike collections which can be traversed many times.
I am not convinced; I don't believe the Stream can ever be null.2. Stream existence check is required
No, a defensive copy is required whenever mutable reference types which are fields enter your object (e.g. via the constructor or a setXXX method) or whenever they leave your object (e.g. via a getXXX method). I do not believe you need to take defensive copies of the Stream because the Stream cannot modify the original Collection. The elements in that Collection may however be mutable themselves, so you will have to decide whether it is necessary to take deep defensive copies or shallow defensive copies.3. Certainly, mutability creates a problem and a defensive copy is required before creating stream Objects.
We have had a look at some of the risks caused by exposing fields of any kind.4. While designing Java APIs, I think, we have to consider many risks and carefully expose Stream inputs and outputs for consumers of the API.
I think that means that Hibernate shows GUI windows when you use that functionality, but I am not certain.. . .
. . .It's windowed and everything
Kenneth A. Kousen, Ph.D. (assorted certs),
President, Kousen IT, Inc, http://www.kousenit.com
- Thanks for the clarification.Kenneth A. Kousen wrote:The Hibernate API now has a stream() method that I believe lets you specify a window of elements to return rather than grabbing all of them and converting the resulting collection to a Stream. I'd have to check the details on that, though -- I only heard about it recently and it's not (yet) in JPA.
That's a pleasure and I am sure that would speak for Ken Kousen too.Narendran Sridharan wrote:. . . Thanks Campbell . . . .
Consider Paul's rocket mass heater. |