我有一个扩展了LinkedHashMap的类(EntireFile)。我试着投:java将LinkedHashMap转换为延伸LinkedHashMap的类
EntireFile old = (EntireFile) functionReturningLinkedHashMap();
它抛出异常,并留言:“java.util.LinkedHashMap中不能转换为com.gmail.maximsmol.YAML.GroupMap”。
public class EntireFile extends LinkedHashMap<String, GroupMap>
public class GroupMap extends LinkedHashMap<String, CategoryMap>
public class CategoryMap extends LinkedHashMap<String, LinkedHashMap<String, Integer>>
请帮我解决错误!
您正在尝试你的LinkedHashMap向下转换到EntireFile。如果转换不起作用,那是因为您的方法返回的对象的运行时类型不是EntireFile。 –