Assuming a list contains no incorrectly typed elements prior to the time a dynamically typesafe view is generated, ...
The generics mechanism in the language provides compile-time (static) type checking, but it is possible to defeat this mechanism with unchecked casts. Usually this is not a problem, as the compiler issues warnings on all such unchecked operations. There are, however, times when static type checking alone is not sufficient. For example, suppose a collection is passed to a third-party library and it is imperative that the library code not corrupt the collection by inserting an element of the wrong type.
No, but adding anything to a raw type is inherently unsafe, so the compiler gives you a warning.
Biniman Idugboe wrote:. . . // Has the unchecked list automatically become a checked list? . . .
So an object of an unchecked type will behave as an unchecked object ...
But a String doesn't have a type. It has several. It is a String, an Object, a Serializable, a Comparable<String>, and a CharSequence. You can see all those types in its documentation.
Biniman Idugboe wrote:Before now, I thought a type and a class were interchangeable. Example, instance of type String and instance of the String class means the same thing. . . .
Looking at the actual runtime type of the object being referenced is the job of the JVM. However, because of Java generics type erasure, the runtime does not even know about generic types, so if you want to have the same kind of type-checking enforcement the compiler gives when you're running your program, you'll need that Collections.checkedList() wrapper.
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
global solutions you can do at home or in your backyardhttps://www.kickstarter.com/projects/paulwheaton/better-world-boo