The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Campbell Ritchie wrote:I have never thought of arrays as immutable
Campbell Ritchie wrote:The advantage of a List is that it changes its size automatically to match the number of elements, both added and removed.
Campbell Ritchie wrote:I think you will make it 3 clock cycles per iteration, too.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Point taken.Tim Holloway wrote:. . . The contents of an array are mutable. The "array" itself, meaning the object that holds those contents, is immutable. . . . .
Tim Holloway wrote:An ArrayList (as far as I know) encapsulates an array (although it could just as easily employ an internal linked list)
Tim Holloway wrote:The contents of an array are mutable. The "array" itself, meaning the object that holds those contents, is immutable.
Campbell Ritchie wrote:Of course, if “immutable” means, “never able to change state,” that would be contingent on its elements being immutable themselves. That latter is an unavoidable problem with all Collection
Paweł Baczyński wrote:
Tim Holloway wrote:An ArrayList (as far as I know) encapsulates an array (although it could just as easily employ an internal linked list)
So it would become a LinkedList.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Does that only apply if you supply an actual type parameter to the List? So...won't compile. There used to be a section in the Java™ Tutorials explaining how a Cage<Lion> differs from a Cage<Butterfly>.Stephan van Hulst wrote:. . . . Lists are invariant, while arrays are covariant. . . . .
Good term; I shall try to remember that.Liutauras Vilda wrote:. . . . In Java 9 this concept is being called "unmodifiable", but not immutable. . . . .
Campbell Ritchie wrote:Does that only apply if you supply an actual type parameter to the List? So...won't compile.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Campbell Ritchie wrote:Does that only apply if you supply an actual type parameter to the List?
Tim Holloway wrote:Are you sure? ArrayList is a subclass of List, presumably Lion is a subclass of Animal. It should be valid at both compile and run times to assign narrower types to more general ones, just not the other way around.
Yes; I even tried it to confirm.Tim Holloway wrote:
I wrote:. . ....won't compile.
Are you sure? . . .
jshell wrote:| Error:
| incompatible types: java.util.ArrayList<Lion> cannot be converted to java.util.List<Animal>
| List<Animal> menagerie = new ArrayList<Lion>();
Don't get me started about those stupid light bulbs. |