what is the point of heterogenous arrays?

后端 未结 8 1216
忘掉有多难
忘掉有多难 2020-12-16 13:43

I know that more-dynamic-than-Java languages, like Python and Ruby, often allow you to place objects of mixed types in arrays, like so:

[\"hello\", 120, [\"w         


        
8条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 14:24

    Here is a simple answer:

    N.B. I am not talking about arrays that include different objects that all implement the same interface or inherit from the same parent, e.g.:

    Everything extends java.lang.Object... and that's plenty. There is no reason not to have Object[] and put anything you like in. Object[] are exceptionally useful in any middleware like persistence layer.

提交回复
热议问题