Type inference in Java
Posted by staufferjames on October 17, 2007 at 12:30 PM EDT
I initial asked about
adding dynamic types to Java but someone pointed out that I probably wanted type inference instead.
So, would type inference be a good fit for Java? Java FX script will have type inference with static tying.
Would
automatic casting be better instead?
Here is a example of how it would be useful (I think/hope):
List list = new ArrayList();
list.add("Hi");
list.add(new Integer(10));
int total = 0;
for(var item : list) {
if(item instanceof String) {
System.out.println("String of length " + item.length);
} else if(item instanceof Integer) {
total += item;
}
}
Related Topics >>
Blog Links >>
- Login or register to post comments
- Printer-friendly version
- staufferjames's blog
- 964 reads





