Because it would break type-safety otherwise.
If not, you would be able to do something like this:
val arr:Array[Int] = Array[Int](1,2,3)
val arr2:Array[Any] = arr
arr2(0) = 2.54
and the compiler can’t catch it.
On the other hand, lists are immutable, so you can’t add something that is not Int
Related Contents:
- When to use a linked list over an array/array list?
- Difference between List and Array types in Kotlin
- Test if array is inside a list in lisp
- Printing array in Scala
- Get specific element in a list or array using EL
- How to pass Scala array into Scala vararg method?
- How to create and use a multi-dimensional array in Scala?
- Why does `Array(0,1,2) == Array(0,1,2)` not return the expected result?
- Excel – Extract substring(s) from string using FILTERXML
- What are the advantages of NumPy over regular Python lists?
- Arrays.asList() not working as it should?
- Swift how to sort array of custom objects by property value
- Not all properties displayed
- Finding three elements in an array whose sum is closest to a given number
- Compare/Difference of two arrays in Bash
- How to find if an array contains a string [duplicate]
- How do I slice an array in Excel VBA?
- What is the ideal growth rate for a dynamically allocated array?
- Using numpy `as_strided` function to create patches, tiles, rolling or sliding windows of arbitrary dimension
- How do I concatenate or merge arrays in Swift?
- Pick a random element from an array
- Why isn’t [SomeStruct] convertible to [Any]?
- How can I extend typed Arrays in Swift?
- Creating Indicator Matrix
- Making my function calculate average of array Swift
- TypeScript array to string literal type
- Shorthand to test if an object exists in an array for Swift?
- Get-ChildItem.Length is Wrong
- Declare and Initialize String Array in VBA
- How do i define a structure in Matlab
- Working with a List of Lists in Java
- How to pass array as an argument to a function in Bash
- Spark Error:expected zero arguments for construction of ClassDict (for numpy.core.multiarray._reconstruct)
- How do I sort a swift array containing instances of NSManagedObject subclass by an attribute value (date)
- How to divide a set into two subsets such that difference between the sum of numbers in two sets is minimal?
- Why am I having issues assigning a Range to an Array of Variants
- Are there other common “c-like” or non “c-like” languages with non zero index array position? [closed]
- Is it possible to make an Array extension in Swift that is restricted to one class?
- Find the 2nd largest element in an array with minimum number of comparisons
- MongoDB – Query on the last element of an array?
- Identify duplicate values in a list in Python
- Find all subsets of length k in an array
- How to allocate arrays on the heap in Rust 1.0?
- Creating an extension to filter nils from an Array in Swift
- How is the array stored in memory?
- Why array indexes are zero based in most programming languages?
- How to create a numpy array of lists?
- Convert bytes/UInt8 array to Int in Swift
- PowerShell copy an array completely
- Compare values of two arrays – classic asp