Casting a Generic List
- From: Bryan <BTRichardson@xxxxxxxxx>
- Date: 26 Apr 2007 08:11:09 -0700
Hello all,
Is it possible to cast an entire Generic List somehow? For example,
say I have the following:
public interface Foo {
.....
}
public class Bar implements Foo {
....
}
public class Test {
public List<Foo> getFooList() { .... }
public static void main(String[] args) {
Test test = new Test();
List<Bar> bars = test.getFooList(); // illegal
}
}
Now assume that all the objects in the FooList were indeed
instantiated as Bar objects.
I get a compile error saying it can't convert from List<Foo> to
List<Bar>. I could always just get a list of Foo objects and cast
them to Bars myself, but I'm just wondering if it can be done for me
all at once.
Any suggestions?
.
- Follow-Ups:
- Re: Casting a Generic List
- From: Daniel Pitts
- Re: Casting a Generic List
- From: Ingo R. Homann
- Re: Casting a Generic List
- Prev by Date: Re: Suggestions for a design tool to help in development of a J2EE application
- Next by Date: How to design a web application to manage many server nodes?
- Previous by thread: Smalltalk2Java Framework
- Next by thread: Re: Casting a Generic List
- Index(es):
Relevant Pages
|