문제

I have a fairly complicated hierarchy of types and sometimes run into hard-to-debug type errors. I'm wondering if there's some kind of tool to inquire if type requirements are met.

For instance if I have the following types:

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);
   }
}

The SphereRoller interface will cause a compiler error: Bound mismatch: The type Sphere is not a valid substitute for the bounded parameter <T extends CanRoll & Shape> of the type ShapeRoller<T>

If could inquire about type properties like Sphere instanceof CanSpin, it would help me realize I forgot to add the CanSpin attribute to Sphere.

This is presumably possible in the debugger's expressions view once the application is built and executed correctly, but before then the type errors have to already be resolved.

Is there any tool or add-on for Eclipse that will allow me to make compile-time type inquiries like this?

도움이 되었습니까?

해결책

You can hit F4 ("Navigate - Open Type Hierarchy") with the required type selected to see the entire type hierarchy involved. You don't need runtime evaluation to achieve the goal, if I got things right.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top