3

スーパークラスのメソッドをオーバーライドし、Google Closure Compiler を使用してコードをコンパイルしようとしていますが、型が間違っているという警告が表示されます。

/Users/Jan/dev/cro/public/app/js/LibraryController.js:55: WARNING -
  mismatch of the setState property type and the type of the property it overrides
  from superclass app.Controller
original: function (this:app.Controller, Object): undefined
override: function (this:app.LibraryController, Object, string, string): undefined
app.LibraryController.prototype.setState = function (state, section, article) {

ご覧のとおり、スーパー メソッドが受け取る引数の型を変更したり、返される型を変更したりしていません。

この問題を解決する方法を知っている人はいますか? ありがとう。

明確にするために、個々のメソッドの定義を次に示します。

/**
 * @param {!Object} state The new state.
 */
app.Controller.prototype.setState = function (state) { ... };

/**
 * @param {!Object} state The new state.
 * @param {string} section A section ID.
 * @param {string} article An article ID.
 * @override
 */
app.LibraryController.prototype.setState = function (state, section, article) { ... }
4

1 に答える 1

4

Overridden methods must have the same (or at least very similar) signatures. Specifically, Subclass methods must be able to be used anywhere the base class could be used. See a full discussion: https://groups.google.com/d/topic/closure-compiler-discuss/o_CMZAvFOLU/discussion

The error message you post above shows that the overriding method has more required arguments than the original which is specifically not allowed. You could however have more optional arguments.

于 2012-10-25T13:07:27.767 に答える