Skip to main content
Post Reopened by JacquesB, CPlus, Doc Brown
added 96 characters in body
Added to review
Source Link
CPlus
  • 1.2k
  • 1
  • 10
  • 26

Java never had immutable primitive arrays. However Java does have an immutable List or Map or other collection classes and of course final primitive fields and variables. In Java if you try to make an Object or array final you only make the reference final. The reference will only point to the same actual object but this does not make the underlying object immutable.

One advantage of immutable arrays would be not needing to create defensive copies because the array could be immutable anyway and could be trivially implemented in syntax:

final int[final] array = new int[final]{1, 2, 3, 4};

Is there a particular technical reason for allowing primitives and references to be made immutable but not arrays? What are the specific less obvious implications to immutable arrays that caused them to be left out of Java and why do they apply to arrays specifically but not primitives? What language or implementation features or mechanics are incompatible with immutable arrays and how so? What other parts of the language would not 'add up' if there were immutable primitive arrays?

Java never had immutable primitive arrays. However Java does have an immutable List or Map or other collection classes and of course final primitive fields and variables. In Java if you try to make an Object or array final you only make the reference final. The reference will only point to the same actual object but this does not make the underlying object immutable.

One advantage of immutable arrays would be not needing to create defensive copies because the array could be immutable anyway and could be trivially implemented in syntax:

final int[final] array = new int[final]{1, 2, 3, 4};

Is there a particular technical reason for allowing primitives and references to be made immutable but not arrays? What are the specific less obvious implications to immutable arrays that caused them to be left out of Java and why do they apply to arrays specifically but not primitives? What language or implementation features or mechanics are incompatible with immutable arrays and how so?

Java never had immutable primitive arrays. However Java does have an immutable List or Map or other collection classes and of course final primitive fields and variables. In Java if you try to make an Object or array final you only make the reference final. The reference will only point to the same actual object but this does not make the underlying object immutable.

One advantage of immutable arrays would be not needing to create defensive copies because the array could be immutable anyway and could be trivially implemented in syntax:

final int[final] array = new int[final]{1, 2, 3, 4};

Is there a particular technical reason for allowing primitives and references to be made immutable but not arrays? What are the specific less obvious implications to immutable arrays that caused them to be left out of Java and why do they apply to arrays specifically but not primitives? What language or implementation features or mechanics are incompatible with immutable arrays and how so? What other parts of the language would not 'add up' if there were immutable primitive arrays?

Post Undeleted by Doc Brown, CPlus, maple_shaft
deleted 52 characters in body
Source Link
CPlus
  • 1.2k
  • 1
  • 10
  • 26

Java never had immutable primitive arrays. However Java does have an immutable List or Map or other collection classes and of course final primitive fields and variables. In Java if you try to make an Object or array final you only make the reference final. The reference will only point to the same actual object but this does not make the underlying object immutable.

If you can make Java primitives final and references to objects and arrays final and make fieldsOne advantage of objects final is there a particular reason for there being no syntax to make arrays immutable? An easy way arrays would be not needing to implement such syntaxcreate defensive copies because the array could be immutable anyway and could be trivially implemented in syntax:

final int[final] array = new int[final]{1, 2, 3, 4};

One advantage I see would be not needingIs there a particular technical reason for allowing primitives and references to create defensive copies because the array could be made immutable anyway.but not arrays? What are the specific less obvious implications to immutable arrays that caused them to be left out of Java and why do they apply to arrays specifically but not primitives? What language or implementation features or mechanics contradictare incompatible with immutable arrays and how so?

Java never had immutable primitive arrays. However Java does have an immutable List or Map or other collection classes and of course final primitive fields and variables. In Java if you try to make an Object or array final you only make the reference final. The reference will only point to the same actual object but this does not make the underlying object immutable.

If you can make Java primitives final and references to objects and arrays final and make fields of objects final is there a particular reason for there being no syntax to make arrays immutable? An easy way to implement such syntax could be:

final int[final] array = new int[final]{1, 2, 3, 4};

One advantage I see would be not needing to create defensive copies because the array could be immutable anyway. What are the specific less obvious implications to immutable arrays that caused them to be left out of Java and why do they apply to arrays specifically but not primitives? What language or implementation mechanics contradict with immutable arrays and how so?

Java never had immutable primitive arrays. However Java does have an immutable List or Map or other collection classes and of course final primitive fields and variables. In Java if you try to make an Object or array final you only make the reference final. The reference will only point to the same actual object but this does not make the underlying object immutable.

One advantage of immutable arrays would be not needing to create defensive copies because the array could be immutable anyway and could be trivially implemented in syntax:

final int[final] array = new int[final]{1, 2, 3, 4};

Is there a particular technical reason for allowing primitives and references to be made immutable but not arrays? What are the specific less obvious implications to immutable arrays that caused them to be left out of Java and why do they apply to arrays specifically but not primitives? What language or implementation features or mechanics are incompatible with immutable arrays and how so?

Made more specific that I am not soliciting opinions
Source Link
CPlus
  • 1.2k
  • 1
  • 10
  • 26

Why does What prevents Java not havefrom having immutable primitive arrays?

Java never had immutable primitive arrays. However Java does have an immutable List or Map or other collection classes and of course final primitive fields and variables. In Java if you try to make an Object or array final you only make the reference final. The reference will only point to the same actual object but this does not make the underlying object immutable.

If you can make Java primitives final and references to objects and arrays final and make fields of objects final why is there a particular reason for there being no syntax to make arrays immutable? An easy way to implement such syntax could be:

final int[final] array = new int[final]{1, 2, 3, 4};

One advantage I see would be not needing to create defensive copies because the array could be immutable anyway. What are the specific less obvious implications to immutable arrays that caused them to be left out of Java and why do they apply to arrays specifically but not primitives?

I cannot see how this question is opinion-based. I am asking for the specific reasons that apply to arrays but not other types for not allowing them to be made immutable. An opinion-based question would be asking if Java should support What language or implementation mechanics contradict with immutable arrays or not or if the reasons not to are justified. I am not asking that. I am asking what the specific historical reasons are.and how so?

Why does Java not have immutable primitive arrays?

Java never had immutable primitive arrays. However Java does have an immutable List or Map or other collection classes and of course final primitive fields and variables. In Java if you try to make an Object or array final you only make the reference final. The reference will only point to the same actual object but this does not make the underlying object immutable.

If you can make Java primitives final and references to objects and arrays final and make fields of objects final why is there no syntax to make arrays immutable? An easy way to implement such syntax could be:

final int[final] array = new int[final]{1, 2, 3, 4};

One advantage I see would be not needing to create defensive copies because the array could be immutable anyway. What are the specific less obvious implications to immutable arrays that caused them to be left out of Java and why do they apply to arrays specifically but not primitives?

I cannot see how this question is opinion-based. I am asking for the specific reasons that apply to arrays but not other types for not allowing them to be made immutable. An opinion-based question would be asking if Java should support immutable arrays or not or if the reasons not to are justified. I am not asking that. I am asking what the specific historical reasons are.

What prevents Java from having immutable primitive arrays?

Java never had immutable primitive arrays. However Java does have an immutable List or Map or other collection classes and of course final primitive fields and variables. In Java if you try to make an Object or array final you only make the reference final. The reference will only point to the same actual object but this does not make the underlying object immutable.

If you can make Java primitives final and references to objects and arrays final and make fields of objects final is there a particular reason for there being no syntax to make arrays immutable? An easy way to implement such syntax could be:

final int[final] array = new int[final]{1, 2, 3, 4};

One advantage I see would be not needing to create defensive copies because the array could be immutable anyway. What are the specific less obvious implications to immutable arrays that caused them to be left out of Java and why do they apply to arrays specifically but not primitives? What language or implementation mechanics contradict with immutable arrays and how so?

Post Deleted by Jörg W Mittag, gnat, Doc Brown
added 204 characters in body; edited tags
Source Link
CPlus
  • 1.2k
  • 1
  • 10
  • 26
Loading
[Edit removed during grace period]
Source Link
CPlus
  • 1.2k
  • 1
  • 10
  • 26
Loading
added 131 characters in body
Added to review
Source Link
CPlus
  • 1.2k
  • 1
  • 10
  • 26
Loading
Post Closed as "Opinion-based" by gnat, Greg Burghardt, Jörg W Mittag
Source Link
CPlus
  • 1.2k
  • 1
  • 10
  • 26
Loading