5 ms·
I expect this breaking a few things in fields injection (a la Spring @Autowired[1]) if implemented. [1] https://docs.spring.io/spring-framework/docs/current/sp
by gabriele 11y ago
I expect this breaking a few things in fields injection (a la Spring @Autowired[1]) if implemented.
[1] https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/beans.html#beans-autowired-annotation https://docs.spring.io/spring-framework/docs/current/spring-...
- ygra 11y agoHow would type inference for local variables mess with fields?
- gabriele 11y agoaccording to Spring's documentation[1]: @Autowired is fundamentally about type-driven injection If you replace: @Autowired FooDao fooDao; with something like: @Autowired var fooDao; I'm pretty sure type-driven injection breaks. [1] https://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-autowired-annotation-qualifiers https://docs.spring.io/spring/docs/current/spring-framework-...
- ubertaco 11y agoYeah, but that's a case where "var" is probably the wrong choice anyways, because of the non-obvious "human type resolution" -- i.e. if I'm a human reading this code, I can't obviously tell the type FooDao, where in simple cases like var path = Paths.get("/foo/bar/bonk") I can.
- radq 11y agoThe proposal only applies to local variables with non-null initializers. I'm pretty sure you can't autowire local variables with Spring, and they don't have initializers anyway.
- TheCoelacanth 11y agovar isn't a dynamic type. var is a compiler-inferred static type. `var fooDao;` will refuse to compile because the compiler can't infer the type. `var fooDao = new FooDao()` will still have the type FooDao for fooDao, it is just inferred by the compiler instead of being explicitly declared by the programmer.