为什么这项任务不起作用? [英] Why wont this assignment work?

查看:83
本文介绍了为什么这项任务不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个结果,其中扩展了ArrayList< Results> 。我有一个对象 i ,它有一个函数 i.getResults(),它返回一个 ArrayList ,类型为 ArrayList< Results> 。我正在尝试以下方法:

I've got a class Results which extends ArrayList<Results>. I've got an object i which has a function i.getResults() which returns an ArrayList of type ArrayList<Results>. I'm attempting the following:

Results result = i.getResults();

但是,我遇到类型不匹配错误。为什么我不能做这个任务?如何将其分配到类型结果?

However, I'm getting a type mismatch error. Why can't I make this assignment? How can I assign it to type Results?

编辑:要解释我正在尝试实现的目标..我无法访问到 ArrayList< Results> 代码,我想让它实现某个类,我有结果实现

To explain what I'm trying to achieve.. I don't have access to the ArrayList<Results> code and I'd like to make it implement a certain class which I have Results implementing

推荐答案

你不能 - ArrayList< Results> 不是a 结果结果是一个 ArrayList< Results> 但是,您可以另外指定。

You can't - ArrayList<Results> isn't a Results. Results is an ArrayList<Results> though, you could assign the other way.

这篇关于为什么这项任务不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆