-3

Apologies for the wording, I've been at this all day and I 1/2 don't know what I'm doing.

Line 44 of the source code in the link, I want to make an object array that contains references to object arrays rectangle/words/dates. When I try to reference the objects inside things[0]/things[1]/things[2], I get back addresses and that is it ( Such as System.out.println( things[0] ).

http://pastebin.com/8QMTBruL

I'm pretty sure using the Object superclass is bad practice versus using the Driver object. I had difficulty declaring something like this: Driver [] rectangle = new MyMRects[10];

Thank you for your time!

mmm_robots
  • 43
  • 1
  • 5
  • Well first you will need to subtract π – Tdorno May 12 '13 at 01:16
  • 1
    There is way too much code here. You need to cut out all the fluff and actually post the relevant code segments in this post... – Steve P. May 12 '13 at 01:17
  • 1
    addresses? there are no addresses in java. You will get the original object if has been assigned correctly, but you won't be able to use any of its methods until you cast that object back to its original type. – Sanjay Manohar May 12 '13 at 01:21
  • if you have an array of objects `things` and you do `things[n]` you are gonna get the object in the place `n`, what did you expect it to return? Use `things[n][m]` if you want to access `n`. – 0x6C38 May 12 '13 at 01:22
  • Thank you all for the comments. I've went away from an array and instead implemented a custom class. A lot cleaner and easier to work with. – mmm_robots May 12 '13 at 08:16

1 Answers1

4

I have no idea why you're creating the things array. You don't seem to be using it. In any case, a better approach than an Object[] array is to create a class that holds the variables of the correct type:

class Things {
    public MyMRects  [] rectangles;
    public MyStrings [] words;
    public MyDates   [] dates;
}
Things things = new Things();
things.rectangles = rectangles;
things.words = words;
things.dates = dates;

As far as the problem that you "get back addresses"—that is the default behavior of toString() for an array. To convert an array to a human-readable string, try using the java.util.Arrays class:

System.out.println(Arrays.toString(words));
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521