Skip to main content

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.

automatic casting
be better instead?

Here is a example of how it would be useful (I think/hope):

List list = new ArrayList();
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 >>