~/talk

Local variable type inference: Friend or foe?

Talkat JPoint 2019 · 2019-04-05..04-06· [java]
slides:none on file

Local variables use type inference introduced in Java SE 10 so the compiler fixes the type at declaration and JDK 11 adds lambda parameter var for annotated params. Examples show concrete pitfalls: array initializers fail with var, var forbids uninitialized and null assignments, using the diamond with var backfires because diamond plus var infers Object and primitive literals often become int which can flip logic in bitmasking so primitive literals infer int causing wrong behavior. Use var for local constructors and chained expressions only when the initializer makes the type obvious.

AI-written summary · about

  1. 0:00Intro
  2. 3:30Why add it to Java
  3. 6:22Simple uses
  4. 8:06Using var
  5. 10:20Try with resources
  6. 12:02Variable type inference
  7. 13:34Making a variable final
  8. 15:36Action of the distance
  9. 17:11Jumping variable names
  10. 18:37Edge cases
  11. 20:14Null
  12. 21:46Types
  13. 23:50Use of literals
  14. 26:23Use of diamond operator
  15. 28:11var
  16. 33:29lambda parameters
  17. 35:43intersection types
  18. 40:21audience question
  19. 46:43guidelines
~/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.