[英]Returning ITERABLE type in Eiffel
I am trying to return Result type being ITERABLE[K]. 我试图返回结果类型为ITERABLE [K]。 All I know is that Iterable inherits from ITERATION_CURSOR, so that I made following unworking code but it doesn't compile.
我所知道的是Iterable继承自ITERATION_CURSOR,因此我编写了以下无效代码,但未编译。
obtainKey (v: V): ITERABLE[G]
local
myCollection: ITERABLE [G]
myCursor:ITERATION_CURSOR[G]
do
create {ITERABLE[G]} myCursor
Result := myCursor
My guess is that I have to do something like following, if it was c++ or Java, 我的猜测是,如果是c ++或Java,我必须执行以下操作:
ITERATION_CURSOR myCursor = new ITERABLE;
I don't know. 我不知道。 My assumption could be wrong.
我的假设可能是错误的。
How can I do this kind of thing in Eiffel and make above code work? 我如何在Eiffel中做这种事情并使上面的代码起作用?
The ITERABLE class is a deferred class (abstract in java) and a deferred class cannot be created. ITERABLE类是延迟类(在Java中为抽象类),因此无法创建延迟类。 You have to use a class that is not deferred and that inherit from the ITERABLE class.
您必须使用一个不延迟的类,该类继承自ITERABLE类。 Note that the ITERATION_CURSOR class is also deferred.
请注意,ITERATION_CURSOR类也被延迟。 What to use can change depending of what you need in your implementation.
使用的内容可以根据实现中的需要而改变。 Here is an example using a LINKED_LIST:
这是使用LINKED_LIST的示例:
obtain_key (v:V): ITERABLE[G]
local
my_list:LINKED_LIST[G]
do
create my_list.make
Result := my_list
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.