Re:Java 10 – Specification for Value Types
by bskap on Monday June 19, 2017 @12:01PM
(#14587925)
The canonical example in the standard library would be this one from the entire collections framework:
You cannot turn an ArrayList<T> into a T[], for example, without passing a T[] into the function so that you can grab the type from the passed parameter at runtime. C#, which retains the generic information at runtime doesn't need this so you can just do
The other place I've seen this come up is with Exceptions- you cannot catch a generic Exception. It's pretty annoying now that Java 8 has streams because you cannot have a checked exception abort out of processing a Stream unless you either 1) catch Exception (rather than the specific subclass) and deal with everything or 2) catch the checked exception in the lambda, wrap it in a runtime exception, rethrow it, and then catch the wrapped exception.
[ Parent
| on HN ]
There are no comments on this comment yet.