B
Brian J. Sayatovic
I have an abstract base class, and a subclass that is nested in
another unrelated class, like this:
public abstract class Base {
public abstract String getName();
}
public class AnotherClass {
protected static class Subclass extends Base {
public String getName() {
return "Subclass Name";
}
}
}
At runtime, I retrieve a list of AnotherClass instances. I want to
iterate through each, casting them to Base, and get their names. Now,
I'm doing this via Struts' taglibs using the logic:iterate and
bean:write tags. Internally, the bean:write tag uses reflection with
the JavaBean rules to look for a "getName" method corresponding to the
"name" property I'm asking Struts to write out.
In practice, through, I get a NoSuchMethodException. As soon as I
change the protection of AnotherClass to public (from protected), it
works.
Now, as I understand it, using straight Java code, I can get an
instance of AnotherClass and call getName() on it because its parent
class, Base, guarantees that getName() is public. Is this not true?
If it is true, then why doesn't reflection honor this as well?
FWIW, I'm using IBM's 1.3.1 JVM (inside WebSphere) on Windows XP.
Regards,
Brian.
another unrelated class, like this:
public abstract class Base {
public abstract String getName();
}
public class AnotherClass {
protected static class Subclass extends Base {
public String getName() {
return "Subclass Name";
}
}
}
At runtime, I retrieve a list of AnotherClass instances. I want to
iterate through each, casting them to Base, and get their names. Now,
I'm doing this via Struts' taglibs using the logic:iterate and
bean:write tags. Internally, the bean:write tag uses reflection with
the JavaBean rules to look for a "getName" method corresponding to the
"name" property I'm asking Struts to write out.
In practice, through, I get a NoSuchMethodException. As soon as I
change the protection of AnotherClass to public (from protected), it
works.
Now, as I understand it, using straight Java code, I can get an
instance of AnotherClass and call getName() on it because its parent
class, Base, guarantees that getName() is public. Is this not true?
If it is true, then why doesn't reflection honor this as well?
FWIW, I'm using IBM's 1.3.1 JVM (inside WebSphere) on Windows XP.
Regards,
Brian.