Is there an Eclipse interactive debugging tool to evaluate type properties?
-
13-11-2019 - |
문제
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.