Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why this object invoke this method?

Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an question puzzled me all the time.The "HelloHome" is a interface extends javax.ejb.EJBHome and this interface has a method "public Hello create()...". The Hello is another interface extends javax.ejb.EJBObject and has a method "public String getHello()...".The HelloEJB is a class implements SessionBean and add a method "public String getHello(){ return new String("hello");" In testing code:"HelloHome home=(HelloHome)javax.rmi.PortableRemoteObject narrow(objRef,HelloHome.class);Hello bean =home.create(); out.println(bean.getHello());".I really don't know why the "bean.getHello()" will work property.Because the bean is a interface and nobody implement it.Does the "home.create()" create a class that implements the "Hello" interface?Someone say that is the J2EE Container implements it.But the method "getHello()" is implemented by HelloEJB other than EJBObject.I think it easy to understand if the code is:
/* in implement class */
class HelloEJB implements Hello......
public String getHello(){
return new String("Hello");
.... ...... ........ ......
/* in testing class*/
Hello bean=new HelloEJB();
/* End */
But mycode doesn't use create method.So I think the "create()" method implements the code I write above and it's the Web Container implements the create method.It's right?Have someone help me?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic