The Source for Java Technology Collaboration
User: Password:
Register | Login help    

Search

Online Books:
java.net on MarkMail:


Type inference in Java

Posted by staufferjames on October 17, 2007 at 9:30 AM PDT
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 >> Programming      
Comments
Comments are listed in date ascending order (oldest first)