Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Data Structure  RSS feed

 
Tye Solan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object Name=new Object("Type", Parent);

E.g
Object Cube=new Object("Part", Root);
Root.Cube.Name="Cube4";
Root.Cube.Position=new Vector2D(0, 2);

How would I be able to make that?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12541
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an example isn't really specs. Tell us what you really need to do.

I'm guessing you'll need a String, a reference to your class type, and a vector for the position...



then, write the various constructors/setters/getters.
 
Campbell Ritchie
Marshal
Posts: 55677
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with Fred about inserting data via your constructor. It is not good design to be able to write myFoo.field1.field2.
You don't say what Root is, but I would suggest you follow Fred's suggestion, assuming that fits the rest of the class. Label all your fields private, so you can't use the join-the-dots syntax.
 
Rob Spoor
Sheriff
Posts: 21087
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And never give your classes names of any existing classes from the java.lang package, like Integer, String or Object. You wouldn't be the first to get compiler errors because you meant java.lang.Object but were actually using your own Object class because it was in the same package.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!