New syntax for interface casting
wysohn opened this issue ยท 0 comments
Currently, when a method of an instance is invoked, it simply uses the exact class of the instance as shown here:
But as of Java9, since the module system prevents accessing classes that are not explicitly open
, so it's crucial that we must use the appropriate class, which is open to public, to avoid the module access problems.
At code level, this can be easily done with the method:
by using the interface/abstract class as the
clazz
parameter.
However, in the TRG script, this is not a valid option. Therefore we will need a new grammar to allow users to 'cast' the instance and invoke the instance's method as the child of the interface/abstract class than directly accessing the method of the child class.
if the con
is an instance that has class A, and A inherits HttpsURLConnection, then before invoking abc()
method of the con
, it will be first casted to HttpsURLConnection
then will invoke abc()
of HttpsURLConnection, instead of abc() of the instance con
directly.