Re: Java language and library suggestions
chucky wrote:
2. allow to specify character encoding for PrintStream. Java 6 SE's
PrintStream prints the characters in platform's default character
encoding.
Streams don't get character encodings.
4. Sometimes having to catch an exception that will never be thrown is
really annoying.
For example, I would like to write something like
@safe
URI uri = new URI("http://valid.uri.com/");
instead of
URI uri;
try {
uri = new URI("http://valid.uri.com/");
} catch(URISyntaxException e) {
throw new AssertionError(e);
}
That's not the language, that's the API. The API designer makes that
decision. They do it on purpose.
There is no way the library can know that the exception will never be thrown,
because there is no way the library can know that you will never make a
mistake with the argument to the method. Therefore your statement that the
"exception will never be thrown" is inaccurate. Remember, method arguments
deal with the general case of all possible inputs, not the specific input you
happened to give it on Saturday.
I used the annotation notation, but I doubt something like this can be
achieved with annotations. It would be nice if the language had a
construct to mark some code exception safe and if it threw an
exception, it would result in AssertionError. It could also be more
flexible, like this
@safe(NumberFormatException, UnsupportedEncodingException)
{
// statement that should not throw any NumberFormatException or
UnsupportedEncodingException
// and if it does, it is an AssertionError
}
This is no more simple than guaranteeing that the argument is correct. What
is your beef with catching exceptions anyway? How hard is it? It's not like
you're hauling rocks; you're just typing a few extra characters.
--
Lew