AutoRefactor
AutoRefactor copied to clipboard
Investigate refactorings for Java 1.8
#See http://www.techempower.com/blog/2013/03/26/everything-about-java-8/ :
- interfaces with static methods and default method implementations.
- instantiate
@FunctionalInterfacewith lambdas, - automatically convert code to do it- use of methods references to do this
- Add
@FunctionalInterfaceto single method interfaces - Generic type inference improvements - remove more types
- Collections API additions - big opportunity here!!
- Ex:
Collection.removeIf()is O(n) forArrayListrather than O(n2) - Ex: static
Collections.sort(list, comparator)=>List.sort(Comparator) - Ex:
Map.computeIfAbsent()to simplifyMultiMapusage - See Collections Refueled talk at JavaOne 2016
- Ex:
java.util.function- can anything be done automatically here?java.util.stream- can anything be done automatically here?java.time- can anything be done automatically here?- See http://stackoverflow.com/questions/19431234/converting-between-java-time-localdatetime-and-java-util-date
- and http://blog.progs.be/542/date-to-java-time
- Reflection and annotation changes - can anything be done automatically here?
- doclint - fix javadocs automatically
java.util.Optional- can anything be done automatically here?- newer helper methods: static methods on
Comparator(ex:comparingInt()),Objects::nonNull(), etc. - Other miscellaneous additions to
java.lang,java.util, and elsewhere - can anything be done automatically here? - From SonarQube:
Also see https://blog.jetbrains.com/upsource/2016/08/03/what-to-look-for-in-java-8-code/
Functions allow to easily build Comparators with https://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html#comparing-java.util.function.Function-
- String.chars()
- StringJoiner and String.join()
- Path.lines()
- Path.walk()
- Collection.removeIf()
- Comparators. comparing().thenComparing()
- New methods on List, Map, ConcurrentMap, etc.
- AtomicLong.updateAndGet()
- AtomicLong.accumulateAndGet()
Refactoring loops into collection pipelines: http://martinfowler.com/articles/refactoring-pipelines.html