[12] in java-interest
more queries: exceptions, new and package
daemon@ATHENA.MIT.EDU (Jeremy Fitzhardinge)
Mon Apr 24 12:08:23 1995
From: jeremy@sour.sw.oz.au (Jeremy Fitzhardinge)
To: java-interest@java.Eng.Sun.COM
Date: Mon, 24 Apr 1995 16:32:14 +1000 (EST)
Hi again.
Most of these questions are things which arn't addressed explicitly rather
than real ambiguities.
The new operator:
What is its precidence? I've made it about the same as unary ops,
so it isn't confused with normal array operations (eg, so you have
to use (new int[10])[4] to index a newly created array).
Can simple types have initializers? That is, new int(12) makes a
reference to an int initialized with 12.
Do constructors for complex types have to have parens? Is (new
Thing) meaningful on its own?
I'm confused about references. Are all variables references to
their instances, or are simple objects really there and complex
ones references? For example, what is the type of the expression
"new int;"? Is it just an int, in which case the new does nothing?
What if I really want an int reference?
Exceptions:
If you have something like
try {
foo();
} catch(specific_thing a) {
...
} finally {
tidy();
}
and foo() throws something which specific_thing doesn't match, does
the finally block get run, as the exception passes through, or
would you need to catch and rethrow Object to get that effect?
The syntax I'm using for try/catch/finally blocks is:
tryblock: "try" block
("catch" "(" arg ")" block)*
{"finally" block}
;
That is, catch and finally blocks have to be directly adjacent to
try blocks, and it's possible to have a try block with no catch or
finally. Is this OK?
Also, is the argument to a catch block allowed to shadow another
local variable? Is it just like a local variable declaration with
a scope of the catch block?
The "package" statement:
The spec says in 6.1 that a package declaration must be the first
non-comment thing in a file. However, I've found that a number of
files in the Java Alpha2 distribution (for example,
classsrc/net/InetAddress.java) have import statements before their
package statement, which javac accepts. Is it wrong, or is the
spec wrong?
Casts again:
I've changed my parsing to match javac; that is, a (simple_type
("[" "]")*) is always a cast. I also made it that (e1) op e2 is
always a cast if op can only be a unary operator, but is a binary
expression if op could also be binary.
Thanks,
J
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com