Results 1 to 5 of 5
Thread: constructor question
- 03-20-2010, 05:47 PM #1
constructor question
Class A contains the following line
Class AssignVariablesDC3Java Code:AssignVariablesDC3 p = new AssignVariablesDC3(12);
Has a constrtuctor
Later on in class AJava Code:int length; public AssignVariablesDC3(int dc3LineLength) { this.length = dc3LineLength; }
In class AssignVariablesDC3 there is a method:Java Code:trim = currentLineArray[p.getTRIM_POSITION()].equals("yes") ? true : false;
Length is always 0. Why not 12?Java Code:public int getTRIM_POSITION() { return (length * FIELDS_IN_SOURCE_OR_TARGET + FIELDS_IN_SOURCE_OR_TARGET + TOTAL_TAGS + TOTAL_ENVIRONMENTS); }
Object is “new”ed only one time
Sysout in constructor confirms “12” was received
- 03-20-2010, 07:31 PM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
I can only guess there is a bug somewhere else in your code. Use a debugger and set a watch on the length instance variable.
Pardon me for ranting a bit, but AssignVariablesDC3 is a terrible name for a class. Classes are blueprints for creating objects, and should have nouns for names. If the sole purpose of that class is to manage properties or data for some other class or some system, then call it PropertyAssigner or DataManager or something like that. Use verbs for method names, and nouns for class names. You'll be happier and saner for it.
-Gary-
-
I agree with Gary: you have a bug and the code with the bug in it is not the code you've posted.
- 03-20-2010, 08:17 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
-
My own thought though was that the object that he's using the length property is not the same object that had the length property set. But I have to admit that I'm not using my regular crystal ball which is in the shop but am making do with a loaner that's one of last year's models.
Similar Threads
-
Question mark colon operator question
By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 08:49 AM -
Java Constructor Question
By ashly in forum New To JavaReplies: 6Last Post: 03-09-2010, 02:10 AM -
Constructor
By Sarinam in forum AWT / SwingReplies: 1Last Post: 06-19-2008, 08:03 AM -
Calling constructor of parent class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:10 AM -
Calling constructor of same class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:01 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks