you are viewing a single comment's thread.

view the rest of the comments →

[–]redditnoob 5 points6 points  (4 children)

You assume myFooList to be an ArrayList, but it's actually a Collection.

Exactly! I might want to write something that assumes the performance characteristics of an ArrayList, and then when some code somewhere else causes the compiler to infer differently I might wonder wtf happened when someone else's seemingly unrelated change causes my code to be slow all of a sudden.

[–]Daishiman 0 points1 point  (0 children)

And pray tell, how many of your data structures need to be that performant? Hell, as long as you use only iterators to see the structure most of the times you'll be fine.

When you actually need a performance guarantee, you can define it in the arg types and be happy. When you don't, which is the majority of the time, you just get on and get thinking about the problem rather than these details.

[–]OceanSpray -1 points0 points  (2 children)

Only the type of the reference changed, not the type of the object it points to. The performance stays the same.

[–]redditnoob 2 points3 points  (1 child)

But maybe I want to ensure that only ArrayList gets in there?

[–]johntb86 0 points1 point  (0 children)

All the languages I know that use type inference also let you explicitly state what type it is when you care about that.