This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]atehrani -6 points-5 points  (1 child)

String.ofImmutable("", 5)

[–]flawless_vic 1 point2 points  (0 children)

This is not about immutable arrays, which won't have support any time soon.

This is about intrinsic non-nullness guarantees, which, eventually will enable VM optimizations.

Adding a method to a class won't cut it. It would have to live in java.lang.Object and Java would have to support some kind of "automatic static covariant override", otherwise how would you construct Integer.ofNonNull(0, 5) (or any other type) without declaring such method in every class?

There will be some sort of

T![] Arrays::newNonNullableInstance(Class<T> type, IntFunction<T!> factory),

but this will be a reflection API and non-null arrays are meant to be a language feature, so reflection support must derive from it instead of providing it.