Java in Notes/Domino Explained: Can I cast a null pointer?


In short – yes you can. There is nothing that prevents you from compiling the following:

String s1 = (String)null;

I even think you’ll have to do it to make your code compile for one for the methods of lotus.domino-package. I can’t of the top of my head remember which method it is, but there is one method where the compiler will force you to cast a null to a String. You’ll also sometimes end up casting a null pointer when doing dynamic classloading.

I told you it would be a short post.

2 thoughts on “Java in Notes/Domino Explained: Can I cast a null pointer?”

  1. Yep, you’re correct. The method is NotesFactory.createSession().

    When trying to create to connect through NRPC, you can use createsession(null, null, null). Unfortunately, this matches several different method signatures.

    To let the compiler know which method you want to call, you have to cast all parameters to String, since the signature will be unique in this case. Thus:

    Session s = NotesFactory.createSession((String) null, (String) null, (String) null);

    Like

Comments are closed.