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

2018-01-26 Thread Kevin Rushforth
jeffrey kutcher wrote: VBox class hierarchy shows getChildren() is implemented in Parent and Pane. vbox.getChildren() returns an instance of Parent which is protected rather than public found in Pane. Accessing the List returned by Parent is an illegal reference because it is protected

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

2018-01-26 Thread jeffrey kutcher
VBox class hierarchy shows getChildren() is implemented in Parent and Pane. vbox.getChildren() returns an instance of Parent which is protected rather than public found in Pane. Accessing the List returned by Parent is an illegal reference because it is protected while accessing the List

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

2018-01-25 Thread jeffrey kutcher
VBox class hierarchy shows getChildren() are implemented in Parentand Pane. vbox.getChildren() returns an instance of Parent which isprotected rather than public found in Pane. Accessing the Listreturned by Parent is an illegal reference because it is protectedwhile accessing the List returned

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

2018-01-18 Thread Jochen Theodorou
Am 18.01.2018 um 14:59 schrieb jeffrey kutcher: In this example, if I can access and execute the method vbox.getChildren().add() with no warnings or errors, which is accessing a non-public class In Java the static type is the important one. Of course you can do VBox vbox = //

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

2018-01-18 Thread jeffrey kutcher
In this example, if I can access and execute the method vbox.getChildren().add() with no warnings or errors, which is accessing a non-public class, then I should also able to access that very same class and execute the same method using reflection with no warnings or errors and expect the

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

2018-01-16 Thread David Holmes
On 16/01/2018 11:08 PM, jeffrey kutcher wrote: Trying to find documentation for the method resolution process. The JVMS defines the rules for method resolution (and subsequent selection). David -- Found this: https://stackoverflow.com/questions/6021109/java-runtime-method-resolution

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

2018-01-16 Thread Kevin Rushforth
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

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

2018-01-16 Thread jeffrey kutcher
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 wrote: There are many good reasons for using non-public classes in the implementation of a

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

2018-01-16 Thread Kevin Rushforth
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

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

2018-01-16 Thread jeffrey kutcher
Thanks Dalibor. On Tuesday, January 16, 2018, 7:45:55 AM CST, dalibor topic wrote: Try https://docs.oracle.com/javase/specs/jls/se9/html/jls-15.html#jls-15.12.4 for example. On 16.01.2018 14:29, jeffrey kutcher wrote: > Did that. There's nothing in there by

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

2018-01-16 Thread jeffrey kutcher
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

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

2018-01-16 Thread dalibor topic
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 -- Dalibor Topic |

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

2018-01-16 Thread jeffrey kutcher
Trying to find documentation for the method resolution process. Found this: https://stackoverflow.com/questions/6021109/java-runtime-method-resolution which leads to http://www.cowtowncoder.com/blog/archives/2010/12/entry_436.html Maybe this is an opportunity for someone to put together a

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

2018-01-16 Thread Peter Levart
On 01/15/2018 11:02 PM, David Holmes wrote: I recall a very similar discussion in the past. You have to start with (public) statically known types, not with the dynamic type of the instances involved. In essence you have to reflectively emulate the method resolution process that occurs with

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

2018-01-15 Thread David Holmes
On 16/01/2018 4:27 AM, jeffrey kutcher wrote: Thanks for your thoughts Jochen. I have a section of code that does just that; function search and casting return values. Not easy ... nor as easy as it should be. You would think however, that if a function call would cause no issues, say

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

2018-01-15 Thread jeffrey kutcher
So developers have to be concerned with how the underlying classes are implemented and code to the implementation. This breaks the contract that is fundamental to Java. For example, the point to garbage collection was don't worry about how garbage collection works. Write your code in the pure

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

2018-01-15 Thread Alan Bateman
On 15/01/2018 18:27, jeffrey kutcher wrote: I've worked with Java since 1995. This example represents an issue that was never an issue up until Java9. Even then, I had no idea it was my code that was the issue since my code never directly referenced illegal classes. I code to write once, run

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

2018-01-15 Thread jeffrey kutcher
Thanks for your thoughts Jochen. I have a section of code that does just that; function search and casting return values. Not easy ... nor as easy as it should be. You would think however, that if a function call would cause no issues, say vbox.getChildren().add(x), that there should

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

2018-01-15 Thread Jochen Theodorou
Am 12.01.2018 um 22:49 schrieb Michał Zegan: well you rather know what getChildren returns, so you know what the returned object is, like generally. but as soon as the method you want to call is not on the statically declared type, nor within a set of known statically types you are having

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

2018-01-12 Thread jeffrey kutcher
The idea is not to be specific, but to be general. This is an example. In practice, I don't know what "o" is and so there has to be a discovery phase. I'm not sure how to make it more general than discovering the class via o.getClass(). As in this example, yes the class object returned is an 

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

2018-01-12 Thread Michał Zegan
Actually, shouldn't reflection be fixed so that you can invoke any method of a non exported class, if the method overrides one that is accessible to the class calling invoke... Not sure it makes sense... W dniu 12.01.2018 o 20:25, mandy chung pisze: > > > On 1/12/18 10:26 AM, jeffrey kutcher

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

2018-01-12 Thread mandy chung
On 1/12/18 10:26 AM, jeffrey kutcher wrote: m = o.getClass().getMethod("add", new Class[] { Object.class, }); o = m.invoke(o, new Object[] { button1, }); o.getClass().getMethod(...) is an anti-pattern for finding a public method.   Object.getClass() returns the

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

2018-01-12 Thread Peter Levart
Hi Jeffrey, See my answer inline... On 01/12/18 19:26, jeffrey kutcher wrote: This is a good discussion but none of the suggestions satisfy the need I'm looking for.https://stackoverflow.com/questions/450807/how-do-i-make-the-method-return-type-generic The example code below shows

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

2018-01-12 Thread jeffrey kutcher
This is a good discussion but none of the suggestions satisfy the need I'm looking for.https://stackoverflow.com/questions/450807/how-do-i-make-the-method-return-type-generic The example code below shows button0 being added to a VBox. It also shows button1 being added to the same VBox only