Draft JEPs for primitive class features

Suminda Sirinath Salpitikorala Dharmasena sirinath1978m at gmail.com
Wed Feb 10 06:08:20 UTC 2021


Hello,

Very much looking forward to the day this is in Java.

When designing the primitives it would be good to have an equivalent of
java.lang.Number in the type hierarchy so these can be used in generics.
And possibly a marker interface to distinguish between Floating point and
Integer type numbers for the benefit of generics and generalisation.

   - Marker Interfaces
      - NumberType
      - IntegerType <: NumberType
      - FloatingPoint <: NumberType

In https://bugs.openjdk.java.net/browse/JDK-8251554 you mention.
> Array types are also subtypes of IdentityObject.

I would very much like if Arrays are both a primitive object and identity
object. When it comes to small arrays it is helpful in some cases if they
are primitive objects so there is no pointer referencing to get to the
array.

Also the current type hierarchy regarding arrays is inadequate and when
different types of arrays are needed one needs to resort to use Object. To
make it easier to use with generics and generalisation, please
consider introducing marker interfaces. Maybe one can introduce an Array
marker interface which represents all arrays.

   - Marker Interfaces
      - Array
      - NumberTypeArray <: Array
      - IntegerTypeArray <: NumberTypeArray
      - FloatingPointArray <: NumberTypeArray
   - Array Objects
      - IdentityObject & Array
      - IdentityObject & Array
      - PrimitiveObject & Array
      - PrimitiveObject & Array
      - IdentityObject & IntegerTypeArray // & Array & NumberTypeArray
      - IdentityObject & IntegerTypeArray // & Array & NumberTypeArray
      - PrimitiveObject & IntegerTypeArray // & Array & NumberTypeArray
      - PrimitiveObject & IntegerTypeArray // & Array & NumberTypeArray
      - IdentityObject & FloatingPointArray // & Array & NumberTypeArray
      - IdentityObject & FloatingPointArray // & Array & NumberTypeArray
      - PrimitiveObject & FloatingPointArray // & Array & NumberTypeArray
      - PrimitiveObject & FloatingPointArray // & Array & NumberTypeArray

Covariance and contravariance is achieved w.r.t the markers.

User defined value types and their respective arrays can have their own
markers.

Suminda

On Wed, 10 Feb 2021 at 03:49, Dan Smith <daniel.smith at oracle.com> wrote:

> I've drafted the following JEPs to cover the initial preview of the
> Valhalla project's core features:
>
> ---
>
> Primitive Objects (Preview)
> https://bugs.openjdk.java.net/browse/JDK-8251554
>
> Describes primitive objects and classes, and the language's use of
> reference and value types.
>
> ---
>
> Unify the Basic Primitives with Objects (Preview)
> https://bugs.openjdk.java.net/browse/JDK-8259731
>
> Describes language and library changes to treat the basic primitives (int,
> double, etc.) as special primitive class types, replacing boxing/unboxing
> with standard reference/value conversions.
>
> ---
>
> Please look them over and make sure they reflect your understanding of the
> features. Most of this has been discussed previously, but these are the
> most comprehensive summaries of the feature set that we've put together.
> (And quite possibly some of it is new to you, or I left something important
> out!)
>
> There will be a third major component, Universal Type Variables, to cover
> the interaction of erased generics with primitive value types. I'm working
> on that one currently.
>
> My intent is to submit all three to become Candidate JEPs in the near
> future, and then we'll pursue the formal specification, implementation, and
> review processes in parallel over the coming months. These are preview
> features that will probably be delivered all together when they're ready,
> no earlier than 18.
>
>


More information about the valhalla-spec-observers mailing list