java casting a list

Posted by dcp on Stack Overflow See other posts from Stack Overflow or by dcp
Published on 2010-03-31T18:18:30Z Indexed on 2010/03/31 18:23 UTC
Read the original article Hit count: 498

Filed under:
|
|

Let's say I had:

protected void performLogic(List<Object> docs) {
  ...
}

In the code where I'm going to be calling this method, I have a List<String> list. I want to call performLogic, passing this list. But it won't work because the lists are 2 different types:

public void execute() {
    List<String> docs = new ArrayList<String>();
    performLogin(docs);  // won't work
}

I tried casting to List<Object> also, but that won't work either.

So is the only way to do this is to make a new ArrayList of Object and just add the values and then pass it? Just seems cumbersome. I wondered if there was a better way to do it.

Thanks.

© Stack Overflow or respective owner

Related posts about java

Related posts about list