"Property must be initialized" error depending on where the class is declared

Answered

I found that the "Property must be initialized" error can occur or not with the same class declaration, depending on WHERE the class is declared.

Is there an explanation for that? I checked the decompiled Java code and it looks the same for both classes.

Here is the code (further down another screenshot without the initialization of 'someInt2' and the compiler error showing.

 

The same code without the initialisation:

 

0
3 comments
Avatar
Yaroslav Bedrov

Hello Roland,

It's expected behavior. Please see related discussion: https://youtrack.jetbrains.com/issue/KT-14260

0

Hi Yaroslav. I understand the impact of the custom setter to some extend. But this does not explain, why there is no such error, when the class is definded within a function (i think that is a 'inner class'). Check the class with the same name 'MyClass' that is defined within the 'main' function. There is no compilier error even though there is the custom setter.

0
Avatar
Yaroslav Bedrov

Roland,

I reported issue on YouTrack: https://youtrack.jetbrains.com/issue/KT-31417

Please follow it for updates.

 

0

Please sign in to leave a comment.