~/talk

Local Variable Type Inference: Friend or Foe?

Talkat Developer Summit 2020 · 2020-11-21..11-22· [java]
slides:none on file

Local variable type inference arrives in Java SE 10 and is useful for shortening verbose code—works well for try-with-resources, breaking up chained stream expressions and hiding obvious concrete types—but fails on arrays and null initializers, forces literal numbers to infer int (the mask example changes behavior), causes double type inference with the diamond operator (new ArrayList<>() → ArrayList<Object>), requires explicit target types for lambdas, adds JDK11 lambda-param var for annotations, and is a reserved type not a keyword; use var only when the initializer makes the type obvious.

AI-written summary · about

  1. 0:00Introduction to local type inference
  2. 3:56Why Java added var
  3. 6:46Traditional local variable usage
  4. 10:00Introducing var keyword
  5. 12:07Var in try-with-resources
  6. 13:52Var and static typing
  7. 15:41Final and non-final with var
  8. 17:31Readability concerns with var
  9. 19:14Var with long type names
  10. 20:42Var limitations with arrays
  11. 21:45Var and null assignment
  12. 23:53Var requires initializer
  13. 26:23Var with literals
  14. 27:27Var pitfalls with primitive sizes
  15. 29:12Var and diamond operator
  16. 31:41Var infers concrete types
  17. 33:45Var and lambda expressions
  18. 36:54Var with lambda annotations
  19. 37:36Var and intersection types
  20. 41:11Var with non-denotable types
  21. 42:56Var in inner classes
  22. 44:20Var as reserved type
  23. 46:24Var usage puzzlers
  24. 52:01Guidelines for using var
  25. 54:29Conclusion and responsibility
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.