Vote
0
Writing Obfuscated Code Using Java Generics Part 1
Angsuman Chakraborty
November 14th, 2005
Let's begin with a simple example for this installment.
import java.util.Collection;
public class TestType {
public static Collection myMethod(Collection a) {
return a;
}
public static void main(String ... args) {
System.out.println(myMethod("Hello World"));
}
}
Note:
1. The import statement is obviously not required. It has been added for effect.
2. Yes, this code compiles and runs.
What we can learn from this simple example:
1. Yes, you can use any valid identifier as a type name; no need to stick to bland Sun prescribed T, K & V
2. DO NOT use an existing class name as type identifier. It can seriously obfuscate your code.
Filed under Headline News, How To, Java Software, Tech Note |
|
RSS 2.0 |
Trackback this Article
|
Email this Article
You may also like to read |




































