Hacker News new | ask | show | jobs
by StrawberryFrog 5776 days ago
Could you expand on what "program to an interface" means to you in this context, I'm not getting it. Assume that I know what it means in the usual context, of depending on the services of an interface type not a concrete type.
1 comments

With the var keyword the variable will be the exact same type as what you initialize it to, not an interface.

  List<Foo> list = new ArrayList<Foo>();
...is programming towards an interface, whereas

  var list = new ArrayList<Foo>();
...isn't, because the type of list will be ArrayList. I think his point was that with the new Java stuff you could instead do

  List<Foo> list = new ArrayList<>();
...which would then be explicitly programming towards an interface, while still not having to type so bleeding much.
Programming to an interface just doesn't seem so useful within the scope of a method.