Results 1 to 6 of 6

Thread: Method execution problem in java

  1. #1
    Join Date
    Mar 2010
    Posts
    197

    Method execution problem in java

    Hello,
    I have a problem of inheritance which disturbs me because it challenges one from my understanding of java, I hope someone will give me an explanation. Within my team, we have a framework based on which several applications depend, a class is abstract, and each application must be classified under this class. The method getApplicationName () returns normally the application name, defined in a configuration file. So now I have something that works but is ugly, and I do not understand why the simple version does not work. If someone has an explanation. Any help on this is highly appreciated. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    583

    Re: Method execution problem in java

    Hello,
    See if the following code helps you. Here is the code that I have created check out if it helps.
    Code:
    Public String appnm() {
    	return approp().getName();
    }
     
    Protected static ApplicationProperties approp(){
    		
    	if (proper == null){
    		WebApplicationContext cnt = WebApplicationContextUtils.getWebApplicationContext(ServletContext);
    proper = ApplicationProperties)cnt.getBean("proper");
    	}
    	return proper;
    }

  3. #3
    Join Date
    Mar 2010
    Posts
    197

    Re: Method execution problem in java

    Hello,
    This is my updated code, have a look at it
    Code:
    abstcnt ctx = abstcntt.getCurrentContext(request);
    ctx.getapp();
    And I use this
    Code:
    appcnt ctx =(appcnt)abstcnt.getCurrentContext(request);
    ctx.getApplicationName();
    Code:
    And also this
    abstcnt tmpCtx = abstcnt.getCurrentContext(request);
    Method mth = Class.Class.forName(tmpCtx.getClass().getName()).getMethod("getApplicationName", null);
    out.print(mth.invoke(tmpCtx, null));

  4. #4
    Join Date
    Nov 2009
    Posts
    446

    Re: Method execution problem in java

    Hello,
    Please check the following code I have modified it, see if this works now.
    Code:
    <% = abstcnt.getCurrentContext(request).getApplicationName()%>
    --
    <%
    abstcnt tpcx = abstcnt.getCurrentContext(request);
    Method mth = Class.Class.forName(tpcx.getClass().getName()).getMethod("getApplicationName", null);
    out.print(mth.invoke(tpcx, null));
    %>

  5. #5
    Join Date
    Nov 2009
    Posts
    330

    Re: Method execution problem in java

    Hello,
    In my opinion on your application server you are always the old version of the superclass, ie one where getapp() is static and the new version of the subclass which contains an instance method getapp(). So when you compile the following code:
    Code:
    abstcnt.getCurrentContext(request).getapp()
    The compiler sees only the superclass, and as for his method getapp() is static. It generates a call to the static method (and thus without inheritance mechanism).

  6. #6
    Join Date
    Nov 2009
    Posts
    335

    Re: Method execution problem in java

    Hello,
    I think the getapp() was static at the parent class, the name of the application was the same for all users of an application. Now, you removed the static level of the superclass, thus redefining the method in subclasses. Each user can have a different application name, as it is stored in context, which is related to the session. I think you get the point I am trying to explain here.

Similar Threads

  1. Problem in using random method in java
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 13-02-2010, 02:22 AM
  2. What is method overriding and method overloading in java
    By beelow in forum Software Development
    Replies: 3
    Last Post: 17-11-2009, 08:20 AM
  3. Problem with my java method
    By manjava in forum Software Development
    Replies: 3
    Last Post: 17-11-2009, 06:15 AM
  4. Replies: 3
    Last Post: 11-09-2009, 03:28 PM
  5. Java: How can I call one method in another method?
    By biohazard 76 in forum Software Development
    Replies: 3
    Last Post: 16-07-2009, 07:12 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,717,177,217.26508 seconds with 16 queries