Henry Wong wrote:
Have you looked at the Java tutorials?
Not sure why this result is so different. Is it because every time I call readline(), it moves the file cursor up 1?
Greg Charles wrote:Yes, you did. Sorry, Kendall. My admonition against downloading pirated tech books wasn't aimed at you specifically. I just didn't want to talk about pirating without mentioning reasons not to do it.
Greg Charles wrote:Unless the download comes directly from the publisher's site, it's safe to assume that it's a pirated copy. Also this book is still for sale, which is another strong indicator it isn't also being given away free. Remember, downloading a pirated PDF is essentially the same as walking into a bookstore and stealing the book. Authors, particularly technical book authors, work extremely hard to write these books and deserve to be compensated for their work.
Dave Tolls wrote:
Kendall Ponder wrote:
In my program I need to be able to copy a baseball team and modify it so I now have two separate teams. The baseball team is mainly a list of players so I need the second team to have the same information the first team had, but not the same objects so I can change a player stat in the second team without affecting the first team.
Just checking there wasn't some odd requirement that might have another solution.
How many different classes of player do you have for a team?
If it's only a couple then I'd stick the clone bit for a Player into some factory method that simply did the work of deciding what class to create. If that starts to be a problem to maintain then you can always change the method to do something fancier.
Of course whichever method you choose, once other code has a copy of a List it is the work of a moment to create a new List from that copy, or to create a Stream from it, and you now have data which you can manipulate to your heart's content
Dave Tolls wrote:I think it's using reflection to call the copy constructor, so handling the "I don't know what class of object I am creating".
That aside, Kendall, why do you think you need to create copies of the contents of the List?
Why do you think you nee to create a new List?