Max Lybbert
Posts: 314
Nickname: mlybbert
Registered: Apr, 2005
|
|
Re: JavaOne 2010: Upcoming Java Features
|
Posted: Oct 5, 2010 10:43 AM
|
|
> All I can say is: I hope 'program to the interface' wasn't the real reason.
Looking at the proposal ( http://mail.openjdk.java.net/pipermail/coin-dev/2009-February/000009.html ):
> An argument can also be made for more full type inference:
auto map = new HashMap<String, String>();
map.get("Foo"); // map is understood to be a Map<String, String>
> or, alternatively, for a typedef like feature, where type > identiļ¬ers are assigned to longer typenames:
typedef MyMap HashMap<String, List<String>>;
MyMap m = new MyMap();
> Both of these approaches, which are present in the > forthcoming C++ standard, would eliminate a lot of > verbosity, at the expense of (potentially) obscuring the > type of the variable. Neither of these proposals are > precluded by this proposal; one, both or neither can be > done at a later date.
Note, (1) C++0x is not the only language with this "other" kind of type inference, it's in C# and any number of functional languages; (2) implementing both the Java-style type inference and the more common type inference will lead to the need to explain to beginning programmers that var x = new ArrayList<>(); is an abomination because the compiler doesn't have enough information to determine what type of elements can go in x .
|
|