|
| |||||||||
| Tags: exectuion, function, java, method, programming language |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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.
__________________ www.techarena.in |
|
#2
| |||
| |||
| 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
| |||
| |||
| 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(); 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));
__________________ www.techarena.in |
|
#4
| |||
| |||
| 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
| |||
| |||
| 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() |
|
#6
| |||
| |||
| 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. |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Method execution problem in java" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem in using random method in java | Gunner 1 | Software Development | 5 | 13-02-2010 02:22 AM |
| What is method overriding and method overloading in java | beelow | Software Development | 3 | 17-11-2009 08:20 AM |
| Problem with my java method | manjava | Software Development | 3 | 17-11-2009 06:15 AM |
| How to validate form field before execution of a servlet service method | Quattro | Portable Devices | 3 | 11-09-2009 04:28 PM |
| Java: How can I call one method in another method? | biohazard 76 | Software Development | 3 | 16-07-2009 08:12 PM |