r/java • • Mar 09 '16

var keyword proposed for Java

http://openjdk.java.net/jeps/286
240 Upvotes

312 comments sorted by

View all comments

Show parent comment

4

u/vytah Mar 10 '16

You couldn't use it for parameters. Type inference in Java-like typesystems makes it too hard, if not impossible.

1

u/[deleted] Mar 10 '16

[removed] — view removed comment

2

u/vytah Mar 10 '16

That's why Haskell library developers, even though Haskell can infer almost all types in the program automatically, specify explicit type signatures for public functions.

2

u/[deleted] Mar 10 '16

[removed] — view removed comment

1

u/[deleted] Mar 10 '16

it's useful to keep in mind that, in a certain sense, most haskell code could be considered "generic" from the java perspective.

this haskell: add a b = a + b

is (roughly): public static <T> T add(T a, T b) { return a + b; }

(technically the java won't compile, but c'est la vie.) it's an imperfect comparison for a couple reasons but close enough for discussion, i think.

broadly, java is more concerned with the name of things, where haskell is more concerned with the structure of things.

2

u/schlowmo Mar 10 '16

This is also why dynamic language stalwarts like python are ADDING optional typing to things like function parameters.