I am building project in monkeyc (ConnectIq) from Garmin in Eclipse, and I want to use const
instead of var
in my code, but it seems that the const
keyword is not recognized by the compiler. What could be wrong?
My code is:
const PI = 3.14;
Compiler complain like this:
BUILD: ERROR: C:\Path:155 missing '}' at 'const'
If I change const
to var
, everything goes well. Where can be a problem? From Garmin documentation MonkeyC should have const
keyword.
It is neither a bug nor a feature, it is just the way that the language is implemented. The Programmer's Guide explicitly says
Constants are named, immutable values declared with the
const
keyword. These are useful for storing unchanging values that may be used repeatedly throughout code. Constants must be declared at the module or class level; they cannot be declared within a function .
I realized that const
keyword cannot be inside a function, it has to be as a class variable. Then it works. I just do not know if it is a bug or a feature.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.