为什么重写negate会导致Dart中的静态警告 [英] Why does overriding negate cause static warning in Dart

查看:132
本文介绍了为什么重写negate会导致Dart中的静态警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个简单的类如下被认为是静态警告,为什么?

Having a simple class as follows is considered a static warning, why?


操作符'negate'应该返回数字类型

operator 'negate' should return numeric type



 
class Vector {
      final int x,y;
      const Vector(this.x, this.y);

      Vector operator +(Vector v) { // Overrides + (a + b).
        return new Vector(x + v.x, y + v.y);
      }

      Vector operator -(Vector v) { // Overrides - (a - b).
        return new Vector(x - v.x, y - v.y);
      }

      Vector operator negate() {    // Overrides unary negation (-a).
        return new Vector(-x,-y);
      }

      String toString() => '($x,$y)';
    }

    main() {
      final v = new Vector(2,3);
      final w = new Vector(2,2);
      assert((-v).x == -2 && (-v).y == -3); // -v  == (-2,-3)
    }

 


推荐答案

我们有一个开放的错误: http://code.google.com/p/dart/issues/detail?id=3416

We have an open bug for this: http://code.google.com/p/dart/issues/detail?id=3416

这篇关于为什么重写negate会导致Dart中的静态警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆