我的类型层次结构相当复杂,有时会遇到难以调试的类型错误。我想知道是否有某种工具可以查询类型要求是否得到满足。

例如,如果我具有以下类型:

class ShapeTypeDebugging {
   interface Shape {}
   interface CanRoll {}
   interface ShapeRoller<T extends CanRoll & Shape> {
      void Roll(T t);
   }
   interface Circle extends Shape, CanRoll {}
   interface HasThreeDimensions {}
   interface ThreeDimensionalShape extends Shape, HasThreeDimensions {}
   interface Sphere extends ThreeDimensionalShape {} // Oops, forgot Spheres CanRoll
   interface SphereRoller extends ShapeRoller<Sphere> {
      @Override void Roll(Sphere sphere);
   }
}


SphereRoller接口将导致编译器错误:
Bound mismatch: The type Sphere is not a valid substitute for the bounded parameter <T extends CanRoll & Shape> of the type ShapeRoller<T>

如果可以查询诸如Sphere instanceof CanSpin之类的类型属性,那将帮助我意识到我忘记了将CanSpin属性添加到Sphere。

一旦正确构建并执行了应用程序,这大概就可以在调试器的表达式视图中实现,但是在此之前必须先解决类型错误。

是否有用于Eclipse的工具或附加组件,可以让我进行这样的编译时类型查询?

最佳答案

您可以单击F4(“导航-打开类型层次结构”),并选择所需的类型以查看所涉及的整个类型层次结构。如果我做对了,则不需要运行时评估即可达到目标。

10-07 19:22
查看更多