Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Most efficient way of implementing this?

Name: Anonymous 2010-11-06 12:21

Simple situation really. Just being a bit paranoid I guess.

I have a 2D grid full of objects which I need to represent in source.

The grid contains two objects, object 1 and object 2 which both are children of object 3 which is abstract.
 
Now the thing is I can either:
1. Create an ArrayList<ArrayList> list object. ArrayLists don't care what you store in them so this would work. However it's kind of a hack since I don't really need a re sizable list with all the shit and giggles.

2. Create a packer object. That stores both of objects 1 and object 2 without problems and store then Packer[][] grid = new Packer(); .

So what does /prog/'s wisdom have to say about this? 1, 2 or some new brilliant idea?

Name: Anonymous 2010-11-06 12:23

Do you not understand the point of inheritance in statically typed languages, or are you just bad at explaining problems?
Alternatively, use a real fucking language.

Name: Anonymous 2010-11-06 12:24

The problem is Java doesn't let an array store objects of a different type. Just in case the OP wasn't clear enough.

Name: Anonymous 2010-11-06 12:27

>>3
They both inherit from a common interface. Make that the array type. Fucking idiot.

Name: Anonymous 2010-11-06 12:28


class DifferentObject {
  Object obj;
  String type;
}

class Main {
  public static void main(String[] args) {
    DifferentObject[] array = new DifferentObject[10];
    // add.. add.. add..
    String type = array[i].getType();
    if (type.equals("prog")) {
       // do your thing here
    }
  }
}

Name: Anonymous 2010-11-06 12:29

>>2

What are you really suggesting to do? If I make an array of type object3 I don't think Java will let me store anything but object3. Also object3 is abstract and I'd really love to keep it that way. Perhaps typecasting object1/2 to object3? I don't know if that ill work?!

Alternatively, use a real fucking language.

I don't have a choice.

Name: Anonymous 2010-11-06 12:32

>>6
If I make an array of type object3 I don't think Java will let me store anything but object3.
You ``don't think'' it will? Have you even tried it? Learn the fucking language before you bother other people for help.

Also object3 is abstract and I'd really love to keep it that way.
I wish there were some emoticon that could communicate my reaction to this statement.

Name: Anonymous 2010-11-06 13:18

>>7
You have bitch tits.

Name: Anonymous 2010-11-06 13:52

Just get the fuck out OP, get right the fuck out.

Name: Anonymous 2010-11-06 13:54

learn2interface and inheritance

Name: Anonymous 2010-11-06 14:05

Fucking Java, how do they work?

Name: sussman -| XARN 2010-11-06 14:55

Rolf I'm actually surprised. Not a single post off topic. Way to go /prog/!

Anyway it was just a misunderstanding. I did the same thing some weeks ago and forgot to typecast and thought it was actually not legit to create an array of abstract objects. Anyway thanks!

Name: Anonymous 2010-11-06 16:56

Define an interface for creating an object, but let subclasses decide which class to instantiate then decouple the abstraction from its implementation allowing the two to vary independently without violating encapsulation make sure you capture and externalize the object's internal state allowing the object to be restored to this state later.

Name: Anonymous 2010-11-06 18:21

>>12
There's no such thing as an ``abstract object''.  Stop being retarded.

Name: Anonymous 2010-11-06 18:45

>>14
[reverse]YHBT[/reverse]

Name: Anonymous 2010-11-06 18:47

>>15
░█▀▀ ░█▀█ ░█ ░█▀▀ ░░█▀▀ ░█▀█ ░█ ░█░░░
░█▀▀ ░█▀▀ ░█ ░█ ░░░░█▀▀ ░█▀█ ░█ ░█░░░
░▀▀▀ ░▀ ░░░▀ ░▀▀▀ ░░▀ ░░░▀░▀ ░▀ ░▀▀▀░

Name: Anonymous 2010-11-06 18:48

>>16

░█▀▀ ░█▀█ ░█ ░█▀▀ ░░█▀▀ ░█▀█ ░█ ░█░░░
░█▀▀ ░█▀▀ ░█ ░█ ░░░░█▀▀ ░█▀█ ░█ ░█░░░
░▀▀▀ ░▀ ░░░▀ ░▀▀▀ ░░▀ ░░░▀░▀ ░▀ ░▀▀▀░

Name: Anonymous 2010-11-06 18:49


░█▀▀ ░█▀█ ░█ ░█▀▀ ░░█▀▀ ░█▀█ ░█ ░█░░░
░█▀▀ ░█▀▀ ░█ ░█ ░░░░█▀▀ ░█▀█ ░█ ░█░░░
░▀▀▀ ░▀ ░░░▀ ░▀▀▀ ░░▀ ░░░▀░▀ ░▀ ░▀▀▀░

Name: Anonymous 2010-11-06 18:50

#color "blind"

Name: Anonymous 2010-11-06 18:52


#color "blind"

Name: Anonymous 2010-11-06 18:52


#color
"blind"

Name: Anonymous 2010-11-06 18:54










FUCK YOU

Name: Anonymous 2010-11-06 21:16

>>18
Why is there no highlight on the right side of the "L"? You suck.

Name: Anonymous 2010-11-06 23:22

>>23
because it is an
░█▀▀ ░█▀█ ░█ ░█▀▀ ░░█▀▀ ░█▀█ ░█ ░█░░░
░█▀▀ ░█▀▀ ░█ ░█ ░░░░█▀▀ ░█▀█ ░█ ░█░░░
░▀▀▀ ░▀ ░░░▀ ░▀▀▀ ░░▀ ░░░▀░▀ ░▀ ░▀▀▀░

Name: Anonymous 2010-11-27 5:31

Name: Anonymous 2011-02-04 12:19

Don't change these.
Name: Email:
Entire Thread Thread List