2

I would like to write a cast method in Eiffel which takes 'the type to cast to' as a type parameter. Is there a way to pass a type into a method in Eiffel.

The only alternative I can think of is to create a new class for the conversion. Something like:

class
   CAST [G, H]

feature

   cast (in: LIST [G]): LIST [H]
      do
         -- cast code here
      end

Is there a better way to do this in Eiffel. In C# I can specify that a method takes type parameters separate from the class type parameters. Is there a similar feature in Eiffel?

I am using EiffelStudio 6.6.8.3873 GPL.

Thanks.

4

1 回答 1

0

不可能有泛型方法,其中返回类型由 Eiffel 中传递的参数确定。对不起。我遇到了同样的问题。您将返回一个公共超类并使用赋值尝试获取对具有正确类型的返回对象的引用。

于 2011-08-22T18:03:37.880 回答