Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
July 13, 2004 HOW? To Object variable assignment. | ||||
---|---|---|---|---|
| ||||
Porting java code I incidentally stuck with such an easy and stupid problem. Java uses Object variable as 'universal type' for storing 'everything (although it's not a typesafe). How legally to assign variable value of some type to the Object variable in D? Something like on java: ------------- Object [] table = new Object[n]; String key = "some key"; table [0] = key; // legal code ... and vice versa ------------ But for D I stuck: ... Object[] obj = new Object[10]; wchar[] str = "fff"; obj[0] = cast(Object)str; // error: cannot cast from wchar[] to Object What's I make wrong? |
July 13, 2004 Re: HOW? To Object variable assignment. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Blandger | D strings don't subclass Object. What else is being stored in "table"? Is it storing key-value pairs? If so I'd consider using an associative array indexed by wchar[] and declared as Object[wchar[]]. "Blandger" <zeroman@aport.ru> wrote in message news:cd1ahk$170b$1@digitaldaemon.com... > Porting java code I incidentally stuck with such an easy and stupid problem. > > Java uses Object variable as 'universal type' for storing 'everything > (although it's not a typesafe). > How legally to assign variable value of some type to the Object variable in > D? > > Something like on java: > ------------- > Object [] table = new Object[n]; > String key = "some key"; > table [0] = key; // legal code > ... > and vice versa > ------------ > > But for D I stuck: > ... > Object[] obj = new Object[10]; > wchar[] str = "fff"; > obj[0] = cast(Object)str; // error: cannot cast from wchar[] to Object > > What's I make wrong? > > |
July 13, 2004 Thanks to all suggestions! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | "Ben Hinkle" <bhinkle@mathworks.com> wrote in message news:cd1bk3$18ra$1@digitaldaemon.com... > D strings don't subclass Object. What else is being stored in "table"? Is it > storing key-value pairs? It's a DWT code. Something like storing and 'playing' with string key-value but I need time to clarify it. I hoped to run this place fast but now see it will take a time. > If so I'd consider using an associative array > indexed by wchar[] and declared as Object[wchar[]]. Thanks for all responds. I'll try some way. |
Copyright © 1999-2021 by the D Language Foundation