Invoking private methods outside declaring class in AX 2012Continue reading
There are three method accessibility modifiers in X++ language. It is well known knowledge of their purpose, as they are common for many programming languages.
In short, public allows for unrestricted use by any classes, protected – only by derived and declaring, private narrows access to declaring class. So, by theory, we shouldn’t be able to access private method outside declaring class. In X++ this is true and false at the same time. How is it possible? Surprisingly, it is very simple. We only need to cast an instance of our class to the object type – base class from which all other classes are derived. Please apply and run following (pseudo) code and you will see.
public void publicMethod()
info("Hey, I'm public!");
protected void protectedMethod()
info("Hey, I'm protected!");
private void privateMethod()
info("Hey, I'm private!");
public static void main(Args args)
class1 = new TestClass1();
objectClass1 = class1;
I personally see this functionality as a bug, but quite useful one. It happened to me already few times, that I had to invoke some private methods. Normally I would overwrite interested object and change its access modifier. But this approach is definitely not elegant. Firstly, having copy in upper layer can cause some problems when upgrading. Secondly, we globally and explicitly change developer’s will.
Summarizing, both solutions should be deeply considered before use, but one of them seems to be much easier to implement.
There is more. Similarly, we can also invoke private table methods. Of course instead of object type a common must be used.
The retail industry is still dealing with the effects of the pandemic that lasted almost three years. In addition to this, further global events are causing disruption to the supply chain or financial stability of many retailers globally. As the industry confronts new challenges shaped by economic and geopolitical factors, it also faces trends influenced by changing customer expectations and needs. Here are 5 developments and trends to watch.
An interactive, AI-powered support for sales, customer service, marketing, and supply chain - Microsoft Dynamics 365 Copilot leverages generative AI and natural language processing technology to perform simple, yet time-consuming daily tasks that workload employees but can be automated.
Every company management facing a system change wonders what steps should be taken to ensure that this change does not cause turbulence to its business. Identical dilemmas are faced by any IT company that provides services to implement a new system. I will focus on these dilemmas today.
Artificial intelligence (AI) and machine learning (ML) technologies are changing business every day - just as new tools and services are frequently emerging to expand their use cases. PwC estimates that the impact of these technologies on the global economy will add approximately $15.7 trillion to its value by 2030 (1).