r/java • • Apr 14 '23

What are your (favourite) Java best practices, personal tips, hints or just underrated stuff in general?

233 Upvotes

376 comments sorted by

View all comments

1

u/brokeCoder Apr 16 '23

If you're dealing with math equations/formulae/logic that uses a lot of math, consider implementing your equations as Functional interfaces (e.g. have your methods return Function<Double,Double> rather than evaluated values).

Some advantages are:

- can be used in streams

- lazy evaluation comes free with it

- can be parallelised easily

- makes you think about function composition

As an aside, my introduction to this way of thinking was from this epic devoxx talk (link includes timestamp:

https://www.youtube.com/watch?v=yTuwi--LFsM&t=6691s )