Community
Participate
Working Groups
3.1M5a Object.getClass() is treated specially (bug 58666) However this leads to the following API problem. Doc of IMethodBinding.getMethodDeclaration says that for raw and parameterized methods something special happens, but for others the result is same as reveiver. Object.getClass() is neither raw nor parameterized, yet IMethodBinding.getMethodDeclaration returns a different result. For example, class A{ void f(){ getClass(); } } the call to getClass is the Object.getClass method. It's reported as having type Class<? extends A>. But asking for getmethodDeclaration returns a method, declared also in Object but with return type Class<? extends Object> If nothing else, the API should make this special case clear. BTW, it's so strange that the java5 people made this one method so strange. It's declared as Class<? extends Object> and the doc says it actually has a type depending on the type of the receiver. Yet, Object is not a generic class. This is so bizarre.
The method is strictly declared as of type: Class<? extends Object> on the declaration side. Only the compiler is translating this type on the fly when this method gets invoked. Blame the spec.
the problem is that the results returned by JCORE APIs are inconsistent with JCORE docs. The API docs say one thing, and the actual results do another thing. Stricly speaking this is an documentation bug. I think the implementation is allright.
Ok, we can mention this in the spec.
Would this be good enough? /** * <p>Returns the binding for the method declaration corresponding to this * method binding. For parameterized methods ({@link #isParameterizedMethod()}) * and raw methods ({@link #isRawMethod()}), this method returns the binding * for the corresponding generic method. For other method bindings, this * returns the same binding.</p> * * <p>Note: The only exception is the method <code>java.lang.Object.getClass<? extends Object></code>. * When used in code, this method returns the method binding corresponding to its * declaration in <code>java.lang.Object</code>. * </p> * * @return the method binding * @since 3.1 */
what about ? Note: A noticeable exception is the method Object.getClass() which is declared to return Class<? extends Object>, but in reality when invoked its return gets substituted into Class<? extends R>, where R is the receiver type of the method invocation. jim - can you double check phrasing ?
how about ? Note: The one notable exception is the method <code>Object.getClass()</code>, which is declared to return <code>Class<? extends Object></code>, but when invoked its return type becomes <code>Class<? extends </code><em>R</em><code>></code>, where <em>R</em> is the receiver type of the method invocation.
you might want to mention that it is the _static_ type of the receiver, not the run-time type
So we would end up with: Note: The one notable exception is the method <code>Object.getClass()</code>, which is declared to return <code>Class<? extends Object></code>, but when invoked its return type becomes <code>Class<? extends </code><em>R</em><code>></code>, where <em>R</em> is the static type of the receiver of the method invocation, not the runtime type.
I released this version: Note: The one notable exception is the method <code>Object.getClass()</code>, which is declared to return <code>Class<? extends Object></code>, but when invoked its return type becomes <code>Class<? extends </code><em>R</em><code>></code>, where <em>R</em> is the compile type of the receiver of the method invocation.
Verified in 20050330-0500. I will open a new bug report to improve the formatting of the doc. The note should be in its own paragraph.