Rather than spending time trying tricks with Lambdas, you should:

  • Make good use of Generic Types. Declare type parameters & enforce them everywhere. Minimize casting and if instanceOfing.
  • Make illegal states unrepresentible in code.
  • Make your own data classes immutable and final where possible, use proper immutable collections.
  • Use libraries that avoid runtime magic and reflection where pragmatically possible.

Full post here, 9 mins read