November 21, 2005

Weird String code

String String = "String";
String = new String(String);

Pretty confusing if you give this to a java beginner :)

Posted by mvdb at November 21, 2005 06:56 PM
Comments
PMD could catch that! http://pmd.sourceforge.net/rules/strings.html#StringInstantiation Posted by: Tom Copeland on November 21, 2005 08:57 PM
Hi Tom, Does it also catch the confusing naming ? :) Posted by: Martin on November 21, 2005 09:10 PM
Heh, not yet, but that's a good idea for a new rule - don't use identifiers that match a type name! It's along the same lines as when folks define a class com.mycompany.List and then it's hard to tell if you're using that one or the java.util.List... blah. Posted by: Tom Copeland on November 22, 2005 03:55 PM
Post a comment