Will there be "var allByDefault: Int?" Cause an error?

In the section: Properties and fields of the kotlin link, the following examples are written:

var allByDefault: Int? // error: explicit initializer required, default gate and installer implied

However, I am testing the code, and there is no error compiling and running it. Here is my code "

fun main(args:Array<String>){ var allByDefault:Int? } 

So why the documentation says:

error: explicit initializer required, default getter and setter implied

I searched Google for help, but did not find a result that could help me.


@toniedzwiedz's answer solved the problem. It's my fault. I accept a property and a variable.

+5
source share
1 answer
 fun main(args:Array<String>){ var allByDefault:Int? } 

You have var local main method, not a property.

 class MyClass { //this is a property of MyClass that requires some means of initialization var allByDefault: Int? // Error: Property must be initialized or be abstract fun foo() { var local: Int? // this is a local variable defined in the scope of foo, which is fine // ... } } 
+9
source

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