Community
Participate
Working Groups
3.0 in java 1.5 the type domain is infinite even without array types so the traditional type hierarchy is less useful to use (programatically) - there is possibly an infinite number of subtypes or supertypes for a given type. but many analyses need that kind of information - refactoring is one but pretty much anybody who does anything interesting will be in need of that info. with generics these things become pretty complicated, e.g.: List<? extends Integer> is a subtype of List<? extends Number> but List<? super Integer> is a supertype of List<? super Number>. So we would have 1 place that contains that kind of code. Jdt core seems to be the natural location for that kind of logic (the type checker need that anyway). So the request is for API that would allow questions of kind 'isSuperTypeOf'
List<? extends Integer> is NOT a subtype of List<? extends Number> and List<? super Integer> is NOT a supertype of List<? super Number> The old fashion type hierarchies are good enough to resolve type declaration hierarchies. The only refinements would occur when using parameterized supertypes, where in theory, AbstractList<Object> should not be mistaken as a supertype of List<String>.
"List<? extends Integer> is NOT a subtype of List<? extends Number>" Strange, last time i saw the spec it was. (it's also that way in the Torgersen paper). you can assign only one way and every instance of List<? extends Integer> is also a List<? extends Number> so i think the former is a subtype of the latter. Can you clarify what you meant when you said it was not? The api request is for a situation like this: i have 2 bindings in hand, i need to check if one is a subtype of the other. Currently i have to walk all superbindings myself but thay does not cover cases like arrays being subtypes of Cloneable or interfaces being subtypes of Object - i have (and other people too) workarounds for these. But the typechecker must be using some information of that sort as well. Exposing it would save a lot of effort on the client side. Also, because there are infinitely many supertypes of something like "List<? super Vector>", the naive walking up the supertype hierarchy is not enough. But again, the typechecker must have that logic already. This request is for exposing that logic via API.
Sorry I misread your request. I considered subtype to mean subclass/subinterface. Type compatibility rules are indeed far from trivial, and we could expose some functionality to surface TypeBinding.isCompatibleWith(TypeBinding) from our internals.
+1 for a central authority for subtype relationship queries.
*** This bug has been marked as a duplicate of 73676 ***