Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
I am trying to cast from a Collection of AObject's to ArrayList<AObject>, but I get a warning. "Type safety: Unchecked cast from Collection to ArrayList<AObject>.
What I have read about this is that the JVM can't be sure that the Collection contains AObject's and thus give this warning.
However. I have first coded my application in IBM Rational Application Developer 7(Which is Eclipse 3.2) and here I do not get this warning. When I moved over to Eclipse and got rid of the IBM spesifics this warning popped up.
I could not find any reason why this would be fine in RAD7 but not in Eclipse 3.3(or 3.2 though RAD7 is eclipse 3.2++).
Because Eclipse has its own compiler, and it either chose not to warn about this, or simply reports the warning in some other way.
It's a warning, you understand why you get it, so just accept it and move on. Such is life. There are warnings related to Java generics that can't' be resolved without fundamental reorganizations of your code; so don't sweat it.
There's an annotation - @SuppressWarning, I think - that can be used to notate code that would otherwise generate a warning.
I believe it is a good thing to use this in places where you're getting a warning, but you have carefully analysed the code and determined there is no bug. That way, you eliminate the spurious warning.
Spurious warnings get you used to ignoring all warnings, which isn't good. Some warnings will be telling you about real bugs.
One shouldn't get used to just suppressing warnings every time they appear, either. Only after careful checking of the correctness of the code and also checking that there isn't a simple way to modify the code to eliminate the warning properly.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
I have checked in the code which gives me the Collection object that the objects in the Collection are allways AObject so that when I use ArrayList<AObject> that will/should work.
If the code which gives me the Collection object where designed with generics in mind I think this warning would go away. As it stands now it is simply a raw Collection. (That code is external)
However I do not like warnings: I try to fix them if fixing is possible. In this case it was not so I appended the @SuppressWarnings("unchecked")
I am going to test your electrical conductivity with this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth