File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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"
Consider Paul's rocket mass heater.
subject: Cast inside object path
Similar Threads
Threads question
Sooooo Confused!!!
Needs clarification about thread execution
Marcus Green Mock- doubt