簡體   English   中英

埃菲爾鐵塔:功能調用中的實際參數不兼容

[英]Eiffel: non-compatible actual argument in feature call

我不明白為什么會這樣。

  • 如果我說attached {G}可以
  • 如果我什么也沒說,這將是我的預期行為calling_entity:可分離的RELATED_DB_EN​​TITY應該符合(一旦連接)G,即-> DB_EN​​TITY
  • 如果我說DB_EN​​TITY不會
  • 如果我說RELATED_DB_EN​​TITY也可以通過

為什么必須指定{G}

SIT_HANDLER

class
    SIT_HANDLER[G -> DB_ENTITY create default_create, make_from_db_service, make_from_json end]

feature --

    some_feature
        do
            if attached {G} l_rest_request.calling_entity as l_calling_entity then
                db_service.set_item_prototype (l_calling_entity) -- Complains here!!!!!!!!!!!!
                db_service.load_with_relationships (l_rest_request)
            ...
        end
end -- class

REST_REQUEST

class
    REST_REQUEST

feature -- Access
    calling_entity: detachable RELATED_DB_ENTITY -- RELATED_DB_ENTITY inherits DB_ENTITY
...
end -- class

DB_SERVICE

class
    DB_SERVICE [G -> DB_ENTITY create default_create, make_from_db_service, make_from_json end]

feature -- Status setting

    item_prototype: G

    set_item_prototype (v: like item_prototype)
        do
            item_prototype := v
        ensure
            item_prototype = v
        end

...
end -- class

在此處輸入圖片說明

類型RELATED_DB_ENTITY不符合類型G

這是一個為什么的例子。 假設有一個FOO類,它繼承於DB_ENTITY並且具有所有必需的創建過程。 FOORELATED_DB_ENTITY不一致。 對於類型SIT_HANDLER [FOO] ,功能部件db_service.set_item_prototype的參數類型為FOO而表達式l_rest_request.calling_entity的類型為RELATED_DB_ENTITY 不允許將類型RELATED_DB_ENTITY的表達式分配給類型FOO的實體。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM