How does one handle a java method which returns a non-public sub-type via reflection?

Kevin Rushforth kevin.rushforth at oracle.com
Tue Jan 16 15:14:31 UTC 2018


No, the fact that it returns a subtype is irrelevant to a program that 
uses it as an instance of the base class. The key here is to know what 
the formal declaration of the return type is, either statically or via 
reflection (e.g., using Method::getGenericReturnType).

-- Kevin


jeffrey kutcher wrote:
> Then in this case, shouldn't getChildren() not be permitted? You're 
> exposing a non-public sub-type.
>
> On Tuesday, January 16, 2018, 8:23:50 AM CST, Kevin Rushforth 
> <kevin.rushforth at oracle.com> wrote:
>
>
> There are many good reasons for using non-public classes in the
> implementation of a class library, the main one being to keep
> implementation details from leaking into the public API. So while I
> "get" that it causes difficulties in your specific case, I don't agree
> that the solution is to avoid using non-public syb-types.
>
> -- Kevin
>
>
> jeffrey kutcher wrote:
> >  There's nothing in the JLS by that name however, section 4.5 
> Parameterized Types, might be close to what I'm looking for.
> > Even in a single inheritance system, resolving methods and types is 
> a multi-dimensional process.
> > I still say that by not allowing private inner classes, resolving 
> this issue would be much easier (or providing the access methods in 
> the parent class of the private internal class would work also ... 
> calling getChildren() really is a dependency on the underlying classes 
> implementation which I really don't understand why is declared private 
> and not accessible. There has to be a good reason otherwise it should 
> be changed or eliminated [get rid of inner classes]).
> >    On Tuesday, January 16, 2018, 7:21:32 AM CST, dalibor topic 
> <dalibor.topic at oracle.com <mailto:dalibor.topic at oracle.com>> wrote: 
> > 
> > 
> >
> > On 16.01.2018 14:08, jeffrey kutcher wrote> Is there official
> > documentation explaining the method resolution process somewhere?
> > I'd suggest taking a look at the Java Language specification and JVM
> > specification for details.
> >
> > cheers,
> > dalibor topic
> > 


More information about the jigsaw-dev mailing list