该类继承相同类的两个不同的泛型派生

问题描述 投票:0回答:1

通过继承确定可迭代类型的正确方法是什么?

因为不允许继承FOO [像babar]

FOO

class FOO

inherit
    ITERABLE[detachable ANY] -- I know garbage but for DB_RESULT its the case


feature -- Access

    new_cursor: ITERATION_CURSOR[like items.item]
        do
            Result := items.new_cursor
        end

    items: ARRAY[detachable ANY]


end -- class FOO

BAR

class BAR

inherit
    FOO -- I know garbage but for DB_RESULT its the case

    ITERABLE[STRING] -- I know garbage but for DB_RESULT its the case


feature -- Access

    new_cursor: ITERATION_CURSOR[like items.item]
        do
            Result := items.new_cursor
        end

    items: ARRAY[STRING]


end -- class FOO

enter image description here

generics polymorphism generic-collections eiffel
1个回答
1
投票

我建议在类FOO中使用正式的泛型参数:

class FOO [G]
inherit
    ITERABLE [G]

然后,类BAR将提供合适的实际通用参数:

class BAR
inherit
    FOO [STRING]
© www.soinside.com 2019 - 2024. All rights reserved.