objects

Java, using an array of points

I am writing a program in Java, in which I define a class class Point { double x; double y; } Then in a method, I define an array of points, as follows: Point[] line = new Point[6]; In the same method, I have the line line[SampleSize - i + 1].x = i; The first time this statement is hit, the value of its array index i...

How to remove an IList<Class> value using dictionary key.

For example I have a class named Temp then I assigned values to it using an IList<Temp>. After populating the IList<Temp> I created a dictionary and assign an int key to each object. My question is that how do I remove from IList and dictionary the temp_value with the name b and a with a key value of "2"? class Temp { public string ...

Java toString Method (objects)

class Position { private double x,y; private int id; public String toString(Position a){ String words ="(" + a.x + "," +a.y + ")"; return words; So I'm getting a memory address returned here. What am I doing wrong? I want to get the actual values of x and y that were set using setters. I also have getters...

Java objects instanceof

The instructions say: Create an equals method that takes an object reference and returns true if the given object equals this object. * Hint: You'll need 'instanceof' and cast to a (Position) I have: class Position { private double x,y; private int id; public boolean instanceOf(Object a) { boolean isInstance; ...

Does .Net / C#'s speed degrade with increased field depth?

Is there any execution speed difference between the following two lines of code? I cannot tell from looking at the IL: int x = MainObject.Field1; int x = MainObject.Public.Fields.Field1; I know from Delphi (native code), there is no difference. ...

Is storing an object reference in a controls Tag property OK

I'm creating a group of form controls for each object in a list, is it OK to store a reference to the object in the controls Tag property? I'm doing this so I can have a generic Click event on the controls, so when they are clicked I can update a field in the object that they represent. So the click handler will look something like thi...

Python: how can I initialize my empty objects ?

how can initialize empty objects in python ? I need to initialize my class members (for examples tk.frames, vtk visualizations etc) thanks ...

C / Python ctypes shared object introspection libraries/techniques.

Hi, I was looking for a way to list .text section defined symbols on a C shared object loaded on a python program using the ctypes wrapper. In other words, i am trying to get a list of defined functions on a CDLL loaded object. If there is no way to do this with ctypes or library ( or python binding ), another option is a python elf pa...

When you make an ArrayList without specifying the object type, does it create it automatically when you add the first object?

For example, instead of doing ArrayList<ClassName> variableName; you do ArrayList variableName; then later you add an object of type "ClassName" variableName.add(objectName); will that automatically set the type of your array as ArrayList<ClassName> ? ...

Creating objects in Java.

I have the following class: class Position { private double x,y; private int id; private static int count=0; //counts number of times a Position object has been created public Position (double initX, double initY) { x=initX; y=initY; id=count; count++; ...

Java initializing objects

Ok so say I have a class class Ghost { private int x, y, direction; private Color color; Now say I dont explicitly define a constructor, so it just uses the default one. If I were to create a new Ghost object, what value would direction have? 0 right? But I dont know why I keep getting a value of 1 for direction. Anything o...

AS3 removing MovieClips in an array

Anybody any ideas on how to remove children from stage using AS3 if I store the reference to the objects in an array and they exist in different locations i.e they are not all children of the same parent? SomeArray.push(this); ...

Copying an object using a constructor, Java

So lets say I want to make a deep copy of an object, but using its contsructor. So I have: public class PositionList { private Position[] data = new Position[0]; private int size = 0; public PositionList(PositionList other, boolean deepCopy) { if (deepCopy==true){ size=other.getSize(); for (int i=0;i<data.le...

Creating an object with a default constructor

So say I have this class: public class PositionList { private Position[] data = new Position[0]; private int size = 0; Now lets say I create a new PositionList object with the default constructor, so no arguments like so: PositionList list = new PositionList(); Does the new list object have any attributes? Does it have a si...

Deep copy of an object array

I want to make a deep copy of an object array using a constructor. public class PositionList { private Position[] data = new Position[0]; public PositionList(PositionList other, boolean deepCopy) { if (deepCopy){ size=other.getSize(); data=new Position[other.data.length]; for (int i=0;i<d...

Help with simple method, Java

This is really a silly question, but I've been staring at this problem for way too long and I just cant figure out what the problem is: /** * public boolean overlap(int targetX, int targetY) { * Returns true if the target position is sufficient close to this ghost * If target position is 16 pixels or less in the x directi...

AS3 Object List Search with Attribute Value Only

Suppose I have a list of objects of a certain custom type and I need to find an object given only the value of one of its attributes, how do I do it? Eg. // Where user1 ... usern are objects of some class User users = [ user1, user2, user3 ... usern ] // How do I find out the objects that have the "foo" attribute set to "bar" ...

Equals method for objects

I'm trying to write an equals method for objects that compares their fields, and if equal, then true: public boolean equals(Ghost other){ if (this.x == other.x && this.y == other.y && this.direction==other.direction && this.color==other.color) return true; else return...

Looking through an array of objects

I'm trying to write a method that looks through an array of objects for a certain color, which is also an object. public Ghost findFirst(Color c){ for (int i=0;i<ghosts.length;i++) { if (ghosts[i].getColor()==c) return ghosts[i]; else return null; } } So if the col...

Creating a deep copy method, Java

I want to make a deep copy method. I seeked help here the other day with this issue, but that was for a copy constructor. Now I need a regular method. I have the code created (nonworking), but I'm just not understanding it completely. public GhostList deepCopy(){ int length=this.getLength(); GhostList jadeed=new GhostLis...