Hacker News new | ask | show | jobs
by jjoonathan 2933 days ago
How does Go statically type check collections, then? It seems like a pretty common, desirable use-case to me.

I could understand not missing this if you're coming from a dynamically typed environment, but understand that many people aren't.

3 comments

Go can statically type check hash maps, arrays, and channels. If you want some other container type it must be written with a concrete element type in mind.
Wait, really? The language designers gave themselves (effective) generics and then kicked down the ladder afterwards so that other container implementers couldn't follow? That's hilarious.
Yes. And yes.
Why does it need to be fair? Serious question.
It doesn't, obviously, it's just hypocritical and patronizing.
What do you mean?

    void do_stuff(Integer[] integers) {
        ....
    }
    
    do_stuff(new String[]{"1", "2", "3"})
    
    Compiler: whoops, you passed an array of strings when the API called for an array of integers.
Umm don't? Why are you iterating over unknown types?
Right back atcha.