Thibaut wrote:
I migrate a Struts app from jdk 1.4 to jdk1.5
I have warnings I would like to solve :
1) the clone() function
I have a "Type Safety" exeption with this kind of code :
current.setUserRights((TreeSet<Integer>) this.userRights.clone());
2) Cast make a warning :
TreeSet<JobTemplate> mySet = (TreeSet<JobTemplate>)
request.getSession().getAttribute(AcceSessionConstant.JOB_TEMPLATE);
Depending on your IDE (I use Eclipse), you might be able to factor out
the casts into separate methods, and add the @SuppressWarnings(
"unchecked" ) to the new method. So instead of,
public void myFunction() {
current.setUserRights( (TreeSet<Integer>) )this.userRights.clone();
}
You'd have a helper function:
@SupressWarnings( "unchecked" )
public TreeSet<Integer> cloneUserRights( UserRights rights ) {
return (TreeSet<Integer>)rights.clone();
}
And use this method accordingly. Keep in mind that you should probably
be absolutely certain about the real type of the object when you do
this. The whole generic thing is simply syntactic sugar (the runtime
still does the casts), and the warnings are there as a reminder.
- Scott
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]