Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

casting Objects

 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 20711
29
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20880
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic