This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes casting Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "casting Objects" Watch "casting Objects" New topic
Author

casting Objects

Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
I am receiving an Object from this method

public void validate(FacesContext arg0, UIComponent arg1, Object arg2)
throws ValidatorException {}

and on looking into arg2 using Debug variables i noticed it contains two ArrayList, it shows

arg2-------------------------------->Object[2]
[0]------------------------------>ArrayList<E>
[1]------------------------------>ArrayList<E>

Problem is what do i cast arg2 with in order to obtain my two ArrayList?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You would be better off to have your debugger find out what class the object belongs to. Then cast it to that class.
Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
Originally posted by Paul Clapham:
You would be better off to have your debugger find out what class the object belongs to. Then cast it to that class.


Thats what i did when i put a debugger on arg2 it showed Object[2] and when i expanded it i got
[0]------------------------------>ArrayList<E>
[1]------------------------------>ArrayList<E>
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40


arg2-------------------------------->Object[2]
[0]------------------------------>ArrayList<E>
[1]------------------------------>ArrayList<E>

Problem is what do i cast arg2 with in order to obtain my two ArrayList?


Object arr[] = (Object []) arg2;
ArrayList<E> firstArrayList = (ArrayList<E>) arr[0];
ArrayList<E> secondArrayList = (ArrayList<E>) arr[1];

Henry
[ March 06, 2008: Message edited by: Henry Wong ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: casting Objects