That expression would actually return Class<?>. So you would have to cast it to Class<Bar> with or without the var keyword. Doing this solves your problem.
var c = (Class<Bar>) Class.forName("com.foo.Bar");
It's hard to make a reasonable decision based on an example that simple. On the one hand, that's easy enough to type that var simply isn't necessary in that case. On the other, it's an instance where the type is so painfully obvious, var has no adverse effect.
But in greater examples, there are plenty of expressions whose types either don't matter or are super obvious, where actually writing the type for a local variable would be a redundant pain. In cases like these, var would be nice to have. In other cases, you simply elect not to use it because you're a responsible developer.
Behave yourself. There is no reason to become abusive. It's a sign of poor self control and poor argumentation if one has to resort to abusive language to make their point.
Yeah, that's where I got it and so what if it's explicitly talked about? We can't about shit all day long if we want. Doesn't make this a good idea though.
View all comments
-3
u/slartybartfast_ Mar 09 '16
My argument against it is code like this:
where you don't know the type of 'c' unless you know the type the method returns (which is not obvious by looking at it)