• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Migration tips to new Java 8/9 API ?

 
Greenhorn
Posts: 17
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ken,

Congrats for the book!

Do you have tips & tricks how to migrate to the new Java 8/9 API from a more legacy Java code ? Like to move from loops and Iterators to Streams, to use Optional properly on the method return types etc ?

Thanks
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Durim Kryeziu wrote:. . . to use Optional properly on the method return types etc ?

Thanks

And what will happen if you change the return types of methods in a public API?
 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One item which you may find helpful when doing migration is default methods inside of interfaces as noted here:
https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html

Official Oracle Trail wrote:Default methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older versions of those interfaces.

 
Durim Kryeziu
Greenhorn
Posts: 17
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Durim Kryeziu wrote:. . . to use Optional properly on the method return types etc ?

Thanks

And what will happen if you change the return types of methods in a public API?



I meant newly created methods, maybe I stated it wrong, I meant like, if before I wrote a method like this and that, from now on, it's better to write it this way (with Optionals in this case)! Now I think you got the idea what I meant with that
 
gunslinger & author
Posts: 169
16
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IntellIJ IDEA has many refactoring methods available to help migration. For example, they allow you to convert a regular loop with an if statement that puts the results into a collection into a stream/collect combination. There are many more available, too.

That said, I don't spend a lot of time converting legacy code unless I was already planning to refactor it. Still, it's easy enough to do with the right tools. This is especially useful when you can convert to library calls, like changing your own hand-crafted comparators into simple combinations of Comparator.comparing().thenComparing() chains.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic