Re: jboss and jsp problem for generic programming
david wolf wrote:
I am using jboss 4.0.2 and my JAVA_HOME environment variable is set to
the dir of jdk 5.0. However, when I tried to write following code in
the jsp, my jsp code would not compile when the page is browsed, what
is the reason?
I am not familiar with JBoss, but many app servers specify the Java home in
their own config files and completely disregard $JAVA_HOME.
Vector tmpv = new Vector(); //line 1
Vector<Vector> tmpv1 = new Vector(); //line 2
Vector of vectors?? What is the base type of the "inner" vector?
The "new" type has to have compatible genericity with the variable type. You
did not provide a base type in the "new" expression.
The variable type says that each Vector element is itself a Vector, but says
nothing about the base type of that element's Vector. Are you trying to do
something similar to:
Vector <Vector <BaseType>> tmpv1 ...?
If I remove line 2 in my jsp file, it works. I do not understand if
there is anyother config I need to do in order for jboss to use feature
of jdk 5.0 for generic programming?
You might have to modify a JBoss configuration file.
That done, you should fix line 2 anyway:
Vector <BaseType> tmpv1 = new Vector <BaseType> ();
("BaseType" itself can be a generic class, e.g., another layer of
"Collection<T>".)
Bear in mind that Vector methods are synchronized. If this is overkill for
you, consider using java.util.ArrayList instead.
In most cases, the variable type should be the interface supertype of the
actual type.
List <BaseType> var = new ArrayList <BaseType> ();
or
List <BaseType> var = new Vector <BaseType> ();
Now you can change the implementation without breaking the code that depends
on "var".
List <BaseType> var = new TreeList <BaseType> ();
Homework: What drives the choice of one implementation over another?
Hint: Read the API Javadocs for each implementation.
- Lew