jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes Cast inside object path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Cast inside object path" Watch "Cast inside object path" New topic

Cast inside object path

Nicholas Turner
Ranch Hand

Joined: May 24, 2003
Posts: 126
I have this item
public Object getItem( int index )
it returns an Employee class
for easiness it looks like this
public class Employee {
private String sName;
public String getName() { return sName;
so Lets say I have this line
but this wont work cause its an object, how can I cast in the middle of the line like something like this ( and yes I know this wont work but how can I accomplish in one line)
can some one help?
thanks in advance,
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
Originally posted by Nicholas Turner:

You're close... try this:

That way you cast it into Employee before you try to execute getName()

Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
I agree. Here's the link: http://aspose.com/file-tools
subject: Cast inside object path
jQuery in Action, 3rd edition