Results 1 to 5 of 5
  1. #1
    mac's Avatar
    mac
    mac is offline Member
    Join Date
    Dec 2009
    Location
    St. Petersburg, Russia
    Posts
    81
    Rep Power
    0

    Default constructor question

    Class A contains the following line

    Java Code:
    AssignVariablesDC3 p = new AssignVariablesDC3(12);
    Class AssignVariablesDC3
    Has a constrtuctor

    Java Code:
    int length;
    
    public AssignVariablesDC3(int dc3LineLength) {
          this.length = dc3LineLength;
    }
    Later on in class A

    Java Code:
    trim = currentLineArray[p.getTRIM_POSITION()].equals("yes") ? true : false;
    In class AssignVariablesDC3 there is a method:

    Java Code:
    public int getTRIM_POSITION() {
    return (length * FIELDS_IN_SOURCE_OR_TARGET + FIELDS_IN_SOURCE_OR_TARGET + TOTAL_TAGS + TOTAL_ENVIRONMENTS);
    }
    Length is always 0. Why not 12?
    Object is “new”ed only one time
    Sysout in constructor confirms “12” was received

  2. #2
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    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-

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,773
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Fubarable View Post
    I agree with Gary: you have a bug and the code with the bug in it is not the code you've posted.
    Any text editor that supports regular expression searches can easily find text that matches the pattern "length *=".

    kind regards,

    Jos

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by JosAH View Post
    Any text editor that supports regular expression searches can easily find text that matches the pattern "length *=".
    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

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 09:49 AM
  2. Java Constructor Question
    By ashly in forum New To Java
    Replies: 6
    Last Post: 03-09-2010, 03:10 AM
  3. Constructor
    By Sarinam in forum AWT / Swing
    Replies: 1
    Last Post: 06-19-2008, 09:03 AM
  4. Replies: 0
    Last Post: 12-19-2007, 10:10 AM
  5. Replies: 0
    Last Post: 12-19-2007, 10:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •