{"id":110,"date":"2022-01-11T17:06:24","date_gmt":"2022-01-11T17:06:24","guid":{"rendered":"http:\/\/naftalin.info\/maurice\/professional\/?p=110"},"modified":"2022-01-11T23:50:26","modified_gmt":"2022-01-11T23:50:26","slug":"java-generics-and-collections-2e","status":"publish","type":"post","link":"http:\/\/naftalin.info\/maurice\/professional\/2022\/01\/11\/java-generics-and-collections-2e\/","title":{"rendered":"Java Generics and Collections \u2013 2e!"},"content":{"rendered":"\n<p>Yesterday I heard that O\u2019Reilly Media, publishers of <em><a rel=\"noreferrer noopener\" href=\"https:\/\/www.oreilly.com\/library\/view\/java-generics-and\/0596527756\/\" target=\"_blank\">Java Generics and Collections<\/a><\/em>, have approved a proposal for a second edition. This news came from <a href=\"https:\/\/twitter.com\/zanmcquade\">Zan McQuade<\/a>, Programming Languages acquisition editor at O\u2019Reilly, whose strategies for acquiring content include indefatigable patience\u2014she calmly waited out two years of silence from me after I first pitched the idea to her. In fact, I\u2019ve been thinking about it for much longer than that, starting from when I was writing <em><a href=\"https:\/\/www.mhprofessional.com\/9780071829625-usa-mastering-lambdas-group\">Mastering Lambdas<\/a><\/em> in 2014. Despite the title, that book is mostly about Java streams, which since Java 8 have been complementary to collections for processing bulk data. A half-book on collections seemed to need revision from that point on.<\/p>\n\n\n\n<p>But that\u2019s only half the book, and\u2014it\u2019s always seemed to me\u2014the less important half. After all, the original USP of <em>JG&amp;C<\/em> was its co-authorship by Phil Wadler, who was one of the originators of the \u201cGeneric Java\u201d prototype that eventually led to the introduction of generics in Java 5 in 2004. Nowadays few Java programmers will remember how controversial and sometimes difficult generics seemed at their introduction, and how important it was to have an authoritative explanation of their peculiarities. But those have changed little in nearly two decades, even if <a href=\"https:\/\/openjdk.java.net\/projects\/valhalla\/\">Project Valhalla<\/a> seems likely to alter that considerably at some point in the relatively near future, for some value of \u201crelatively near\u201d. Perhaps in another year we\u2019ll know enough about Valhalla to be able to change the generics half of the book in line with it\u2014or perhaps Zan will have to go back in two years\u2019 time to argue for a third edition!<\/p>\n\n\n\n<p>But meanwhile the Java Collections Framework has continued to evolve\u2014perhaps without huge changes, but with enough to justify a revision. Much of this evolution has been adaptation to Java\u2019s journey in the direction of a more functional style. A prime example is unmodifiable collections; although it\u2019s more than four years since they were introduced in Java 9, many people are only now migrating to Java 11\u2014or, equally likely, to Java 17. If the latter, they will encounter records too, so this seems like a good time for an explanation of how these different functionally-oriented features, as well as streams, can work together.<\/p>\n\n\n\n<p>Another reason for a new edition is the ageing of the Java Collections Framework. (Actually, in personal sympathy with this elderly API, I should probably say \u201cmaturing\u201d.) It\u2019s worn very well for an API designed in the last century. (On another personal note, I have to tip my hat here to <a href=\"https:\/\/twitter.com\/joshbloch?lang=en-GB\">Joshua Bloch<\/a>, the designer of the JCF. At a time when I\u2019d given up hope of ever getting the collections material into shape, he very generously provided an extraordinarily detailed, precise\u2014and painful!\u2014technical review, highlighting virtually every one of my many errors, and saving the collections material from disaster.) But <em>JG&amp;C<\/em> was written at a time when the JCF was still only five years old. Nearly two decades on, we have the opportunity for a much more considered design retrospective and for a comparison with other collections frameworks, like Guava and Eclipse collections, that have appeared since then.  <\/p>\n\n\n\n<p>I\u2019m also looking forward to supplying two other elements absent from the first edition. One is a cause of increasing dissatisfaction for me with the collections half of <em>JG&amp;C<\/em>: its discussion of the relative performance of the different collection implementations. I compared them there solely on the basis of their asymptotic (Big-O) performance, without providing any experimental results. That\u2019s quite embarrassing now, after I\u2019ve given so many conference talks on the difficulty and importance of accurate measurement when discussing performance. And since a (half-)book on collections is one place where such discussions are inescapable, I\u2019m looking forward to providing data to back up the theory\u2014or, more likely, to require its modification to fit with modern machine architectures.<\/p>\n\n\n\n<p>I\u2019m feeling quite\u2014perhaps foolishly\u2014confident about this revision, very much in contrast to my feelings approaching the first edition. Much of that is due to already having a technical editor on board, the tireless Doctor Deprecator, <a href=\"https:\/\/twitter.com\/stuartmarks\">Stuart Marks<\/a>. Stuart is ideally placed for this, being the Oracle lead on the Java collections library. He was TE on <em>Mastering Lambdas<\/em>, so I\u2019ve had the pleasure of working with him before, and he\u2019s already provided a lot of the ideas in support of the book proposal, including some in this blog piece. If you\u2019ve read this far (congratulations!) you\u2019ll see there\u2019s quite a lot of work to do, but with Stuart on the team I\u2019m confident that we\u2019re really going to produce something valuable for the working Java programmer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday I heard that O\u2019Reilly Media, publishers of Java Generics and Collections, have approved a proposal for a second edition. This news came from Zan McQuade, Programming Languages acquisition editor at O\u2019Reilly, whose strategies for acquiring content include indefatigable patience\u2014she calmly waited out two years of silence from me after I first pitched the idea [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/naftalin.info\/maurice\/professional\/wp-json\/wp\/v2\/posts\/110"}],"collection":[{"href":"http:\/\/naftalin.info\/maurice\/professional\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/naftalin.info\/maurice\/professional\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/naftalin.info\/maurice\/professional\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/naftalin.info\/maurice\/professional\/wp-json\/wp\/v2\/comments?post=110"}],"version-history":[{"count":17,"href":"http:\/\/naftalin.info\/maurice\/professional\/wp-json\/wp\/v2\/posts\/110\/revisions"}],"predecessor-version":[{"id":132,"href":"http:\/\/naftalin.info\/maurice\/professional\/wp-json\/wp\/v2\/posts\/110\/revisions\/132"}],"wp:attachment":[{"href":"http:\/\/naftalin.info\/maurice\/professional\/wp-json\/wp\/v2\/media?parent=110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/naftalin.info\/maurice\/professional\/wp-json\/wp\/v2\/categories?post=110"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/naftalin.info\/maurice\/professional\/wp-json\/wp\/v2\/tags?post=110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}