LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-21-2011, 08:23 PM   #1
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Rep: Reputation: 30
Java passing iterators to new Objects and returning them


Hello All,

I have created an object where I pass a string and a long value to it <in Java>, currently I am adding the values to my Object so I can then add it to a list like so:


Code:
List myList;
ImageObject io;

for(i = 0; i < 10; i++)
  {
  io = new ImageObject("String", i);
  myList.add(io);
  }

This is what the object currently looks like:
Code:
public final class ImageObject<name, time>
    {
    public String name = "";
    public long time = 0;
    

    public ImageObject(Object o)
        {
        // Think I need something here, but im not sure what!
        }
    
    public ImageObject(String name, long time)
        {
        this.name = name;
        this.time = time;
        }

    public long getTime()
        {
        return this.time;
        }
    }

And this is how I would like to retrieve it:
Code:
        {
        ImageObject io;
        Iterator i = lstPageImages.iterator();

        while(i.hasNext())
            {
            io = new ImageObject(i.next());
            log.printDebug("name: "+io.name+" time: "+io.time);
            }
        }
Does anybody have any ideas? Many thanks in advance.

trscookie.
 
Old 03-22-2011, 03:34 AM   #2
posixculprit
Member
 
Registered: May 2010
Posts: 136

Rep: Reputation: 42
What you are likely looking for is casting:

Code:
while (i.hasNext()) {
  io = (ImageObject) i.next();
  log.printDebug("name: "+io.name+" time: "+io.time);
}

Last edited by posixculprit; 03-22-2011 at 03:35 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing C++ objects to message queues aryan1 Programming 2 08-02-2009 06:22 AM
LXer: Java Data Objects and Service Data Objects in SOA LXer Syndicated Linux News 0 01-17-2009 06:10 AM
java objects zaicheke Programming 3 03-23-2005 06:21 AM
passing passing variable in Java as reference djgerbavore Programming 3 11-10-2004 02:18 PM
Objects in Java? mikeshn Programming 0 06-11-2002 10:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration