Community
Participate
Working Groups
Tim Halloran asks on jdt-core-dev@eclipse.org: If one walks up the type hierarchy using ITypeBindings it appears a bit difficult to figure out you are at the top (e.g., you get null from an getSuperclass() method call). The problem is "null" from this call can reasonably mean a few other things as well. I've compared the fully qualified name to "java.lang.Object" but I'm wondering if there is a better way? Should there be a "boolean isJavaLangObject()" method that returns true if the type is "java.lang.Object", and false otherwise? Thoughts? Jim des Rivieres replies: Since java.lang.Object is the only genuine class without a superclass, you could also use typeBinding.isClass() && typeBinding.getSuperclass() == null Philippe Mulet adds: I suspect though that if the superclass is missing, the binding superclass will also be null. ========== The upshot is that we need to investigate further. (a) How are classes with missing superclasses handled? Is the superclass binding null, or is it a stand-in? Spec does not suggest that there are any "holes" in the binding graph? (b) How about other places? E.g, method bindings with missing parameter types? (c) Should we add "boolean isJavaLangObject()" to ITypeBinding?
You can look at the qualified name of the type binding. If it if 'java.lang.Object' you found it.
(From the jdt-core-dev mailing list) a good approach that maybe should be wrapped into a convience API method...Tim Jim des Rivieres <Jim_des_Rivieres@oti.com> To:jdt-core-dev@eclipse.org Subject:[jdt-core-dev] ITypeBinding - How to tell your at "java.lang.Object"? Date:13 Nov 2002 19:17:46 -0500 Tim, Since java.lang.Object is the only genuine class without a superclass, you could also use typeBinding.isClass() && typeBinding.getSuperclass() == null ---jim
Another idea: From: Dirk Baeumer <Dirk_Baeumer@oti.com> To: jdt-core-dev@eclipse.org Subject: Re: [jdt-core-dev] ITypeBinding - How to tell your at "java.lang.Object"? Date: 14 Nov 2002 18:45:49 +0100 Another idea is to compare the binding with the binding returned from AST#resolveWellKnownType("java.lang.Object"); Dirk
The latter suggestion should be added to the superclass API.
Jim - please update the API
Added the following para to javadoc for ITypeBinding.getSuperclass(): "Loops that ascend the class hierarchy need a suitable termination test. Rather than test the superclass for <code>null</code>, it is more transparent to check whether the class is <code>Object</code>, by comparing whether the class binding is identical to <code>ast.resolveWellKnownType("java.lang.Object")</code>."
Closing. Doc fixed.
Verified.