JSP object naming problem
1 posts in topic
Flat View  Flat View

Posted By:   Steve_Albee
Posted On:   Friday, February 1, 2002 11:29 AM

I've inherited a code base with the following problem:

This translates into compiled code of:

AAAServiceDetail AAAServiceDetail = new AAAServiceDetail();

Obviously, this is extremely bad form. Naming your instantiation of a class the same as the class itself leads to a lot of confusion. What I'm looking for is a strong technical reason why this shouldn't be done this way. The code will compile and run, but now we're experiencing some errors, and this code is suspect.

Re: JSP object naming problem

Posted By:   Bozidar_Dangubic  
Posted On:   Monday, February 4, 2002 08:02 AM

there is no technical reason why this should not be done this way. the only issue that is possible here is that AAAServiceDetail.someMethod() call is confusing to read because your class and object are named the same and it is confusing whether this is a call to a static method in AAAServiceDetail class or a call to a method on the object AAAServiceDetails. but the JVM will have no problem resolving this. since you cannot have a static method on a regular method with the same name and the same signature, JVM can figure out what you are trying to do and will execute correctly invoking a static method when you mean AAAServiceDetail as a class and regular method when you use AAAServiceDetail as an object. However, this is a horrible code and you should rename id in the jsp:useBean to something else like aaaServiceDetail.
About | Sitemap | Contact