Java Language Specification

From EggeWiki
Revision as of 03:15, 5 November 2007 by Egge (talk | contribs)

I've been reading the Java Language Specification to improve my knowledge of the Java language. Here's a list of things I've learned:

$ identifier

The $ character can be part of a Java identifier. "for historical reasons, the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024). The $ character should be used only in mechanically generated source code or, rarely, to access preexisting names on legacy systems."

This means I can make my Java programs look like Perl. <geshi lang="java5"> public class Test<$> { int $$;String $0="$";$ $; $ $(){if($$==0)System.out.println($0!=$?$0:$);return $;} public static void main(String args[]) { new Test().$();} } </geshi>


Assignment Conversions

"A narrowing primitive conversion may be used if the type of the variable is byte, short, or char, and the value of the constant expression is representable in the type of the variable."

This means this is legal:

<geshi lang="java5">

       final int x = 255;
       short y = x;

</geshi>

But this is not. <geshi lang="java5">

       int x = 255; // not final
       short y = x;

</geshi>

I found it's interesting that this works for byte, short, and char, but not for long.