Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

class LinkedList
Hi!
By using the class LinkedList, I wrote a method, that returns a list of
Elements of the type of a class, I wrote too.
Now I want to access a method of the first Element by using the method
getFirst() (this should return an element of the type of the class in my
opinion) and then the method name. But as the type of the returned
Element is now Object, I can only access the methods of the class Object
and not of the class, I thought my Elements would be a type of.
Thank you.

Report this thread to moderator Post Follow-up to this message
Old Post
Heiko Fleischmann
10-27-04 01:57 PM


Re: class LinkedList
Hi Heiko,

That's because LinkedList only knows how to link Objects. But since you
happen to know that your Element is also an Element, you can cast it
back to an Element:
Element xxx = (Element)list.getFirst();
If you are using JDK 1.5 (J2SE 5.0), you could also have a look at
generics, which offers a much nicer and safer solution.
See http://java.sun.com/developer/techn.../J2SE/generics/
Good luck, Paul.

On 27-10-2004 12:40, Heiko Fleischmann wrote:
> Hi!
> By using the class LinkedList, I wrote a method, that returns a list of
> Elements of the type of a class, I wrote too.
> Now I want to access a method of the first Element by using the method
> getFirst() (this should return an element of the type of the class in my
> opinion) and then the method name. But as the type of the returned
> Element is now Object, I can only access the methods of the class Object
> and not of the class, I thought my Elements would be a type of.
> Thank you.

Report this thread to moderator Post Follow-up to this message
Old Post
Paul H. van Rossem
10-27-04 08:59 PM


Re: class LinkedList
Paul H. van Rossem wrote:
> Hi Heiko,
>
> That's because LinkedList only knows how to link Objects. But since you
> happen to know that your Element is also an Element, you can cast it
> back to an Element:
> Element xxx = (Element)list.getFirst();
> If you are using JDK 1.5 (J2SE 5.0), you could also have a look at
> generics, which offers a much nicer and safer solution.
> See http://java.sun.com/developer/techn.../J2SE/generics/
> Good luck, Paul.
>
Hi Paul!
Thank you for your quick response!
I think I got it now.
Best regards!
Heiko.

Report this thread to moderator Post Follow-up to this message
Old Post
Heiko Fleischmann
10-27-04 08:59 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:55 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.