I'm trying to cast a list of Objects to a list of my own class type. So far what I'm doing is:
List<Company> companies = (List<Company>)(Object) repository.findAllCompanyNames();
repository.findAllCompanyNames()
is returning a List<Object>
My Company class looks like:
public class Company {
public Company(){}
public Company(int id, String name){
this.id = id;
this.name = name;
}
public int id;
public String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
I don't get any error the problem is the value of companies
after the cast, it is:
companies = {ArrayList@11743} size = 4
0 = {Object[2]@11753}
0 = {Integer@11761} "1"
1 = "Company 1"
1 = {Object[2]@11754}
0 = {Integer@11785} "3"
1 = "Company 3"
2 = {Object[2]@11755}
0 = {Integer@11779} "4"
1 = "Company TT"
3 = {Object[2]@11756}
0 = {Integer@11764} "5"
1 = "Company 34"
4 = {Object[2]@11757}
and I think the companies
list should contain Company objects like:
- Id: 1
- Name: Company 1
- etc ..
Any idea what it's going on?