Nice, but I prefer C# there as well where you use the var keyword, like this:
var tickets = new ArrayList<Ticket<ThingYouLove>>();
Actually, JDK7 is better in this case because it helps developer to "program to an interface". Nice, but I prefer C# there as well where you use the var keyword, like this:
var tickets = new ArrayList<Ticket<ThingYouLove>>();
Actually, JDK7 is better in this case because it helps developer to "program to an interface". List<Foo<Bar>> list = new ArrayList<>();
Programming to an interface is relevant between method calls, not inside the scope of a single method, which is typically where you use the var keyword in C#. This is programming to an interface, in C#, using the var keyword: public List<Foo<Bar>> MyMethod(...) {
List<Foo<Bar>> result = new ArrayList<Foo<Bar>>();
...
return result;
}
var list = MyMethod(...); //list will be of type List<Foo<Bar>>
In Java, the above would then look like this: public List<Foo<Bar>> MyMethod(...) {
List<Foo<Bar>> result = new ArrayList<>();
...
return result;
}
List<Foo<Bar>> list = MyMethod(...);
You don't save more characters in either case, neither is promoting programming to an interface more than the other, but I still think the var keyword is the better construct, since it removes type declaration consistently. It basically means that the compiler should infer the type of the variable immediately, without me having to spell it out. The Java construct on the other hand means something like: "In the constructor to a generic class, infer the generic parameters from the type of the variable the result is assigned to", which is a weaker construct, a less expressive one, a less flexible one.Both are still syntactic sugar implemented as compiler tricks, but the C# one simply does more.
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.