Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ClassCastException going from interface to object  RSS feed

 
Alan Smithee
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the class
===================
public class AllStuff implements Serializable {

public List <IBigCar> bigcars;

}


And the following code
=======================

BigCar bc = new BigCar();
bc = (BigCar) this.classname.getAllStuff("uniqueID").getBigCarList().get(0);


This code compiles. Why am I not able to cast an interface from a list to an object?
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the runtime type is actually a BigCar then the cast should work. If you are getting a ClassCastException, then the run time type must not be a BigCar.

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!