My thoughts as an enterprise Java developer.

Wednesday, January 17, 2007

Automatic casting

Is there any downside or problem potential to change the Java compiler to automatically cast? In the example below the result of list.get(0) would automatically be casted to the type of the variable hi.

List list = new ArrayList();
list.add("hi");
String hi = list.get(0);


I know that generics allow you to reduce casting but they do so at the expense of making declaration more difficult. To me, the benefit of generics is that they allow you to have the complier enforce more rules -- not they they reduce casting (but I haven't used them much so I am somewhat uninformed). This proposal would only reduce the amount of code to type, not move it to another place.

No comments: