JDK-4479713 : (reflect spec) Class.get{Declared}Method* does't explain absent implicit methods
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2001-07-13
  • Updated: 2012-09-28
Related Reports
Relates :  
Relates :  
Description

Name: bsC130419			Date: 07/13/2001


java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

The documentation for java.lang.Class.getMethod(String, Class[]), getMethods(),
getDeclaredMethod(String, Class[]), and getDeclaredMethods() are inaccurate
with regards to interfaces.  According to JLS 9.2, ALL interfaces have
implicitly declared public methods, corresponding to the ones in Object, unless
they are redeclared explicitly in the interface hierarchy.  Therefore, the
documentation for these reflective methods needs to clarify that Method objects
are returned only if the interface method is explicitly declared, and that
implicitly declared methods are not returned.

I propose adding this text to each of the 4 methods I listed:
"Public methods declared or inherited in an interface that are defined
implicitly, as mentioned in JLS 9.2, are not visible by reflection."
(Review ID: 128069) 
======================================================================

Comments
WORK AROUND Name: bsC130419 Date: 07/13/2001 Expect a NoSuchMethodException, even though I implicitly declares toString: interface I {} class Foo { void bar() { try { java.lang.reflect.Method toStringMethod = I.class.getMethod("toString", null); } catch (Exception e) { } } } ======================================================================
11-06-2004

EVALUATION Will examine clarifing the relevant JavaDoc. ###@###.### 2002-05-14
14-05-2002