This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I receive the following when trying to compile a servlet (a servlet which attempts to obtain a home interface via a JNDI lookup) C:\ASAservletCode\ASAdonations.java:61: inconvertible types found : java.lang.Object required: RagHome RagHomehome= (RagHome) context.lookup( "Rag" ); ^ 1 error Finished The code in the servlet is: Properties env = new Properties();
RagHomehome= (RagHome) context.lookup( "Rag" ); The compiler obviously knows about RagHome. The context.lookup method returns a Java.lang.object I am attempting a cast of object to RagHome. What am I doing wrong?
It is required to support RMI-IIOP for remote access in EJB. Since CORBA supports a lot of languages, and some of them don't support casting, you need to explicitly narrow the object coming back from lookup(). When you use lookup() and the reference is remote, you always need narrow(). Or, if you need to get remote reference by using Handle, HomeHandle,or EJBMetaData, you need narrow(). There might be other situations that you need narrow() method, but I am not sure. I hope this helps.