I don't get the hint (more static stuff)
Hi list, I wanted to have a static array of strings within a public class. This turns out not to be allowed yet but there is hope; instead of a plain error I got a hint; "cannot declare static non-primitive ojects (yet) (hint; declare as ref (@) and initialise outside for now)" This I don't get. What am I going to reference to what and where do I declare it? Maybe I'm missing something. My reasoning was that I clearly needed something more primitive then a array so a int seemed like a good sort of thing I then declared the trouble maker (the array) outside of the class and tried asign the array to the int. At this ChucK protests (like a thought it should) because arrays and ints are different sorts of things. Now I'm lost. What does this hint mean? Aparently no static strings are allowed at all (and I can't realy see why those are less primitive then ints)? Could somebody get me un-stuck? Thanks, Kas.
Hi Kassen!
I wanted to have a static array of strings within a public class. This turns out not to be allowed yet but there is hope; instead of a plain error I got a hint;
"cannot declare static non-primitive ojects (yet) (hint; declare as ref (@) and initialise outside for now)"
Oh no. You've stumbled upon the disaster within a disaster. The bigger disaster, of course, is that static variables don't work properly yet (you have to initialize Objects outside the class). The nested disaster within that is because strings are treated as primitives in parts of the type-checker, and as objects in others. This is a priority bug but is dependent on garbage collection. Yikes. So, for now, no static strings. You would need a wrapper to achieve the same effect. class StupidHack { string m_str; } public class X { static StupidHack @ our_hack; } new StupidHack @=> X.our_hack; "hello" @=> X.our_hack.m_str; Very very sorry about this... Doh. Best, Ge!
Very very sorry about this... Doh.
Don't be. On further reflection it turned out that the thing I needed wasn't realy static strings and more like public strings that would remain the same for the cource of the program which is way, way easier and just involves defining the string inside of the class, then not touching it. I'll be needing proper static strings later but for now I'm fine. I did indeed stumble upon some quite weird stuff trying to fix it and suspected they were a bit but not completely like primitives already, I think I won't try to get deeper into them untill the fix gets here. My plan was to make some stuff more readble so if it works the simple way for now... Thanks for the explanation, Kas.
participants (2)
-
Ge Wang
-
Kassen