ArrayFactory SAM type (original) (raw)
Remi Forax forax at univ-mlv.fr
Thu Nov 8 09:35:40 PST 2012
- Previous message: ArrayFactory SAM type / toArray
- Next message: Introduce Covariance/Contravariance at declaration site for Java 9 ?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 11/08/2012 05:43 PM, Brian Goetz wrote:
On 9/19/2012 10:27 PM, Raab, Donald wrote:
Could we add the following methods to the Class class?
T[] emptyArray() T[] newArray(int size) I prototyped these, and they work fine for reference types but fall apart for primitive arrays. There is a Class literal for int.class, but we can't make it return an int[] with this method. (This is one reason that Array.newInstance returns Object.) Performance testing would be needed to ensure they are competitive with alternatives. yes, int.class is typed Class, so we have two choices, if the class is a primitive, or we can throw an exception, or it should create an array of the corresponding wrapper types. Given that the current collection API doesn't allow to use array of primitive (because collection.toArray takes an array of T), in my opinion, the best is to provide two methods emptyObjectArray() and newObjectArray(int size) that returns an array of T or throw an exception if the class is a primitive type.
Rémi
- Previous message: ArrayFactory SAM type / toArray
- Next message: Introduce Covariance/Contravariance at declaration site for Java 9 ?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the lambda-libs-spec-observers mailing list