Search |
||
Call me SantaPosted by forax on December 17, 2006 at 7:11 AM PST
Since my last post, i've played with javac enought to be able to provide a patch that enables to let the compiler infers the type of local variables. Life is a matter of choices
If you have already read the last
Peter Ahé's blog entry
you know that, at least, two proposed syntaxes compete.
// print a frequency table of words
public static void main(String[] args) {
map:=new HashMap<String,Integer>();
for(word:args) {
freq:=map.get(word);
map.put(word,(freq==null)?1:freq+1);
}
System.out.println(map);
}
Note that the compiler infers local variable in foreach loop too. The second syntax supported by Peter Ahé and Christian Plesner Hansen use the keyword final to acheive the same goal. My running example with the 'final' syntax:
public static void main(String[] args) {
final map=new HashMap<String,Integer>();
for(final word:args) {
final freq=map.get(word);
map.put(word,(freq==null)?1:freq+1);
}
System.out.println(map);
}
How to use the prototype ?
To enable the Algol syntax, call javac in this way:
or if you prefer the final syntax:
What you can do ?
You can test the prototype and let us know what you thinking.
Download the prototype :
prototype-1.7-b04.jar
Cheers, Rémi »
Related Topics >>
Open JDK Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|