B/c ThinkDifferent is a class, ThinkDifferent.hideMenuBar() would only be allowed if if it happens to be a static method; otherwise weād have to instantiate ThinkDifferent 1st, then invoke hideMenuBar() method over its instance object.
Either the method hideMenuBar() has some access restrictions, such as private or; it might not exist for other platforms besides MacOS!
For either case, weāre required to use reflection techniques in order to access members which have limited access permissions or itās not 100% guaranteed to exist!
Keyword null represents the absence of an Object.
But still, using (cast) operator to identify it as an Object seems like a silly overzealous non-AI IDE advise which most devs trust too much!
As @GoToLoop pointed out null is a value not an object. An object reference having the value null means that it is not referencing any object at that moment.
So the function call .invoke(null) passes a null value and the invoke method must test for null to prevent a NPE (null pointer exception) being thrown.
The alternative .invoke((Object)null) passes a Null Object, so I suspect the developer is using the Null Object Pattern to avoid the null test and provide some default behaviour in the absence of an object.
The null versus (Object)null point just interested so I did a little research and discovered the Null Object Pattern, I have never used this pattern and do not know how to implement it so donāt ask me for further detail.
chains many method invocations so if one throws an exception or fails to perform as expected then it can be quite difficult to find the problem. Separating them until the final code is proven is generally a good idea. You can always chain them together later but why bother hell would freeze over before you saw any efficiency benefit in this particular instance.
Because processing.core.ThinkDifferent.hideMenuBar is indeed static and public (for whatever reason), it should be possible to just call processing.core.ThinkDifferent.hideMenuBar((Object) null).
This method has the native modifier which is a non-access modifier used to access methods implemented in a language other than Java like C/C++.
So it not simply about invoking this method because if you look at the method definition in github you will see that the method has no body so has no implementation rather like an interface or abstract method.
I suspect that the class loader is not just loading the class but linking it to the mac OS so it can invoke the hideMenuBar there.
The sketch below has four methods that use the original Processing code and the alternative of a simple call to the methods in ThinkDifferent class. (Obviously this will only work on osx)
Keys āhā & āsā will hide / show using the original methods
Keys āqā & āwā will hide / show using direct calls to the ThinkDifferent class methods
If you try it they both work with notable feature, once the showMenuBar() method is invoked / called it is no longer possible to hide the menu bar a second time.