commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Carman <ja...@carmanconsulting.com>
Subject Re: svn commit: r989199 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/SerializationUtils.java test/java/org/apache/commons/lang3/SerializationUtilsTest.java
Date Thu, 26 Aug 2010 10:29:18 GMT
On Thu, Aug 26, 2010 at 5:04 AM, Henri Yandell <flamefew@gmail.com> wrote:
>
> I wonder if this could be a findbugs/checkstyle/pmd rule?
>

Why use findbugs for something like this when it's completely obvious
why it's okay?  When you serialize an object and then deserialize it,
you can be pretty sure you're going to get back the same type of
object.  Complaining about this particular piece of code it just plain
nitpicking, IMHO.

I would argue that the deserialize() method should be genericized as such:

public static <T extends Serializable> T deserialize(byte[] bytes);

This way, you could do:

Person p = SerializableUtils.deserialize(bytes);

No casting!  Now, if the bytes don't represent a Person object, then
you'll get a ClassCastException, but that's exactly the same thing
that would happen if you did this (with the current API):

Person p = (Person)SerializableUtils.deserialize(bytes);

So, we make it easier to use the API by avoiding a cast.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message