Pregunta

He escrito una página aquí en el uso de matrices como objetos propios con sus propios métodos en lugar de depender de las clases de ayuda como Arrays, Arrays y ArrayUtils.

ints.sort(); // instead of Arrays.sort(ints);
// instead of int[] onemore = ArrayUtils.add(ints, 8);
int[] onemore = ints.add(8); 

Estoy seguro que no soy el primero con esta idea, pero he tenido problemas para la búsqueda de otros que han escrito sobre esto antes.

Puede alguien ayudarme con algunas referencias sobre este tema?

Se puede añadir comentarios, si usted tiene una referencia sobre por qué esto es una mala idea o una buena idea si usted tiene uno?

Enlace eliminado. Adición de puntos principales

Esto se deduce de la idea de la moneda Proyecto

OVERVIEW
Provide a two sentence or shorter description of these five aspects of the feature:
FEATURE SUMMARY: Should be suitable as a summary in a language tutorial.

array Treat como objetos con sus propios métodos en lugar de valores que se pasa a métodos auxiliares. Esto conduce a una codificación más natural y proporciona los métodos más inmediatez. p.ej. a través de la finalización de código.

MAJOR ADVANTAGE: What makes the proposal a favorable change?

Es traer la programación OO a las matrices, el apoyo a los métodos ya disponibles y por escrito.

MAJOR BENEFIT: Why is the platform better if the proposal is adopted?

consistencia orientado a objetos para las matrices.

MAJOR DISADVANTAGE: There is always a cost.

Alguien tiene que escribir y probarlo.

ALTERNATIVES: Can the benefits and advantages be had some way without a language change?

métodos auxiliares de llamadas.

EXAMPLES
Show us the code!
SIMPLE EXAMPLE: Show the simplest possible program utilizing the new feature.

int[] ints = {5,4,3,2,1};
ints.sort(); // instead of Arrays.sort(ints);
int pos = ints.indexOf(5); // instead of Arrays.asList(ints).indexOf(5); or ArraysUtils.indexOf(ints, 5);
ints.reverse(); // instead of Arrays.reverse(ints);
Array array = ints; // cast to super class.
int length = array.getLength(); // instead of Array.getLength(array);
Object n = array.get(3); // instead of Array.get(array, 3);
array.set(3, 7); // instead of Array.
Object obj = array;
System.out.println(obj); // prints [5,4,7,2,1] instead of having to if (obj instanceof int[]) System.out.println(Array.toString((int[]) obj)); else if (....)
  

AVANZADO Ejemplo:. Mostrar uso (s) avanzada de la característica

int[] ints = {5,4,3,2,1};
int[] ints2 = ints.copyOf(2);
int[] ints3 = ints.subArray(2,4);
ints.sort(myComparator);
List<Integer> list = ints.asList();
Set<Integer> set = ints.asSet();
long total = ints.sum();
double avg = int.average();
int max = ints.max();
int max2 = ints.max(myComparator);
http://commons.apache.org/lang/api/org/apache/commons/lang/ArrayUtils.html
int[] onemore = ints.add(8); // instead of ArrayUtils.add(ints, 8);
int[] moreInts = ints.addAll(ints2); // instead of ArraysUtils.addAll(ints, ints2);
int[] oneless = int.remove(3); // instead of ArrayUtils.remove(ints, 3);
Integer[] integers = int.toObject();
int[] intsAgain = integers.toPrimitive();

DETAILS
SPECIFICATION: Describe how the proposal affects the grammar, type system, and meaning of expressions and statements in the Java Programming Language as well as any other known impacts.

tendría que ser añadido como el padre de todas las matrices de una clase como java.lang.Array. [], Boolean [] pueden también ser necesarios subclases para int específico. La gramática no debe ser radicalmente diferente.

COMPILATION: How would the feature be compiled to class files? Show how the simple and advanced examples would be compiled. Compilation can be expressed as at least one of a desugaring to existing source constructs and a translation down to bytecode. If a new bytecode is used or the semantics of an existing bytecode are changed, describe those changes, including how they impact verification. Also discuss any new class file attributes that are introduced. Note that there are many downstream tools that consume class files and that they may to be updated to support the proposal!

En la proporciona una nueva matriz para las matrices podría ser utilizado, la compilación sería el mismo como lo es ahora. Sin embargo, es la JVM que habría que aceptar que una matriz tiene una superclase diferente.

TESTING: How can the feature be tested?

Comprobar los nuevos métodos de hacer las mismas cosas que los métodos de ayuda. (En caso de ser sencilla si es que acaba de llamar a los mismos métodos auxiliares)

LIBRARY SUPPORT: Are any supporting libraries needed for the feature?

Esto debe añadirse a la rt.jar

REFLECTIVE APIS: Do any of the various and sundry reflection APIs need to be updated? This list of reflective APIs includes but is not limited to core reflection (java.lang.Class and java.lang.reflect.*), javax.lang.model.*, the doclet API, and JPDA.

La superclase para una matriz necesitaría para volver java.lang.Array o similares en lugar de java.lang.Object. Sin embargo, de nuevo este puede ser un cambio para la JVM en lugar del código rt.jar.

OTHER CHANGES: Do any other parts of the platform need be updated too? Possibilities include but are not limited to JNI, serialization, and output of the javadoc tool.

El cambio debe reflejarse en el Javadoc.

MIGRATION: Sketch how a code base could be converted, manually or automatically, to use the new feature.

Reemplazar llamadas a Arrays.xxx (array, args) para array.xxx (args);

COMPATIBILITY
BREAKING CHANGES: Are any previously valid programs now invalid? If so, list one.

Las llamadas a hashCode () y equals () podría cambiarse si se tomaron cada método. Esto puede ser inaceptable en cuyo caso estos métodos podrían ser dejados como son en lugar de Arrays.hashCode llamada () o Arrays.equals ();

EXISTING PROGRAMS: How do source and class files of earlier platform versions interact with the feature? Can any new overloadings occur? Can any new overriding occur?

No.

REFERENCES
EXISTING BUGS: Please include a list of any existing Sun bug ids related to this proposal.

Esto es lo que estoy buscando ayuda en los informes de errores, u otras referencias

¿Fue útil?

Solución

Le sugiero que busque en las distintas clases de colecciones en su lugar.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top