Review: JDK 8 CR for Support Integer overflow updated (original) (raw)
Brian Goetz brian.goetz at oracle.com
Wed Feb 15 05:07:52 UTC 2012
- Previous message: Review: JDK 8 CR for Support Integer overflow updated
- Next message: Review: JDK 8 CR for Support Integer overflow updated
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In your subsequent email, I found that the asXXX and toXXX variants to be too similar to make it clear which throws and which does not or other differences unless it were a pervasive pattern that all developers would know and use.
We encourage this convention:
- Use "asXxx" to describe creating an Xxx view of the object;
- Use "toXxx" to describe converting the object to an Xxx.
There are two dimensions along which you might make the distinction:
- If the object is mutable, a view would reflect state changes to the original, whereas a conversion would not (e.g., HashMap.values());
- Regardless of mutability, "as" suggests a more or less trivial operation (casting, wrapping with a trivial wrapper such as Collections.immutableSet), whereas "to" suggests a heavier operation that involves copying the data (StringBuffer.toString, List.toArray).
In general, "as" operations are perceived as cheaper than "to" operations.
- Previous message: Review: JDK 8 CR for Support Integer overflow updated
- Next message: Review: JDK 8 CR for Support Integer overflow updated
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]