How to generally initialize a value type with its default value?

In the context of the Java Project Valhalla , how can I generally initialize a value type with its default value?

At first, I thought that assigning to nullany type of value would do this initialization. However, the answers and comments to this question clearly show what nulla link is, therefore it has nothing to do with value types (precisely because value types are not links, but direct values).

eg. if I have a value type Personwith attributes StringValueType nameand DateValueType dateOfBirth(here dateOfBirthis a nested type values containing attributes int year, int monthand int day), how can I initialize my Persontype of value a general way , to the values of its attributes are ""for nameand (0, 0, 0)(or appropriate default value) for dateOfBirth, respectively?

To make this clearer, if it were C, I would do:

memset(myPersonStructVariable, 0, sizeof(Person));

Or in modern C:

struct Person myPersonStructVariable = {0};
+4
source share
1 answer

aconst_null (.. null, ), - vdefault. spec:

6.5 vdefault

vdefault indexbyte1 indexbyte2

...

byte1 indexbyte2 (2.6), (indexbyte1 < 8) | indexbyte2. (4.4.1). (5.4.3.1).

(5.5), . (2.3.5) .

2.3.5:

2.3.5

...

- . null .

:

[ ], , 0 .

, , C memset(myStructVar, 0, size).


, , - null, (, MyValueType x = default(MyValueType) - ) . , vdefault. , -.

, (, "" StrinValueType), , ( ). , .


valhalla vm : http://mail.openjdk.java.net/pipermail/valhalla-dev/2017-December/003631.html

+5

Source: https://habr.com/ru/post/1693422/


All Articles