Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Why is system.println printing a reference number

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    10
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why is system.println printing a reference number

    [I am trying to print the output of lot.getHighestBid, which is just a number but for whatever reason, it prints the reference number @234lln. What is wrong with my code?
     
     public void close()
        {
     
            for(Lot lot : lots){
                Bid bid = lot.getHighestBid();
                if(bid != null)
     
     
                {
     
                    System.out.println("Sold to: " + lot.getHighestBid().getBidder().getName() + " for: " + lot.getHighestBid()  );
     
     
     
            }
     
        }
    }


    --- Update ---

    Never mind. Mods could close this thread or remove it. I just found out after hours of scratching my head that I should use lot.getValue() method.


  2. #2
    Member Chris.Brown.SPE's Avatar
    Join Date
    May 2008
    Location
    Fort Wayne, Indiana
    Posts
    190
    Thanks
    1
    Thanked 31 Times in 31 Posts

    Default Re: Why is system.println printing a reference number

    For other people looking at this same problem. If this is showing for a class that you built, it may be beneficial to overwrite the toString() method. For instance if you do it the way shown below. Saves headaches and will also help if you are debugging in Eclipse. The variables display with their toString() values.
    @Override
    public String toString() {
    	return this.getValue();
    }

Similar Threads

  1. System.out.println Error when using Iterator
    By willo009 in forum Collections and Generics
    Replies: 7
    Last Post: August 30th, 2013, 02:08 AM
  2. System.out.println Not Working
    By manjula in forum JavaServer Pages: JSP & JSTL
    Replies: 6
    Last Post: November 27th, 2012, 07:25 AM
  3. How to modify System.out.println()
    By emailkia in forum Java Theory & Questions
    Replies: 6
    Last Post: April 25th, 2011, 12:40 AM
  4. what is System,out,println in System.out.println()?
    By koteshk in forum Java Theory & Questions
    Replies: 2
    Last Post: April 18th, 2011, 12:28 AM
  5. How can i print rows 1 by 1 using System.out.println?
    By noFear in forum Java Theory & Questions
    Replies: 2
    Last Post: August 26th, 2010, 07:35 AM