Domanda

Ho scritto una pagina qui sull'utilizzo di array come oggetti propri con i propri metodi, invece di basarsi sulle classi di supporto, come array, array e ArrayUtils.

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

Sono sicuro che io non sono il primo con questa idea, ma ho avuto problemi alla ricerca di altri che hanno scritto su questo prima.

Qualcuno mi può aiutare con alcuni riferimenti su questo argomento?

Si può aggiungere commenti se si dispone di un punto di riferimento sul perché questo è una cattiva idea o una buona idea se ne hai uno?

cancellato. L'aggiunta di punti principali

Ciò deriva dal concetto di progetto Coin

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 Trattare come oggetti con metodi propri anziché valori da trasmettere ai metodi helper. Questo porta alla codifica più naturale e fornisce i metodi più immediatezza. per esempio. attraverso il completamento del codice.

MAJOR ADVANTAGE: What makes the proposal a favorable change?

Si mettono programmazione OO agli array, sostenendo metodi già disponibili e scritto.

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

Oggetto Orientato consistenza per gli array.

MAJOR DISADVANTAGE: There is always a cost.

Qualcuno deve scriverlo e testarlo.

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

Metodi di chiamate di supporto.

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 (....)
  

avanzata Esempi:. Mostra l'utilizzo avanzato (s) della funzione

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.

Una classe come java.lang.Array dovrebbe essere aggiunto come la madre di tutti gli array. [], [] Potrebbe anche essere necessario per sottoclassi specifiche int booleano. La grammatica non dovrebbe essere drammaticamente diverso.

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!

Nel fornisce un nuovo genitore per gli array potrebbe essere utilizzato, la compilazione sarebbe lo stesso come è ora. Tuttavia, è la JVM che avrebbe bisogno di accettare che una matrice ha un super classe diversa.

TESTING: How can the feature be tested?

Controllare i nuovi metodi di fare le stesse cose, come i metodi di supporto. (Deve essere semplice se davvero basta chiamare gli stessi metodi di supporto)

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

Questo dovrebbe essere aggiunto alla 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 classe di super per una serie avrebbe bisogno di tornare java.lang.Array o simili, invece di java.lang.Object. Tuttavia, ancora una volta questo può essere un cambiamento per la JVM, piuttosto che il codice 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.

La modifica dovrebbe riflettersi nel javadoc.

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

Sostituire chiamate a Arrays.xxx (array, args) per array.xxx (args);

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

Chiamate a hashCode () e equals () sarebbe cambiato se ogni metodo sono state prese. Ciò può essere inaccettabile nel qual caso tali metodi potrebbero essere lasciati come sono, piuttosto che chiamata Arrays.hashCode () 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.

Questo è quello che sto cercando aiuto su, segnalazioni di bug o altri riferimenti

È stato utile?

Soluzione

Vi suggerisco di guardare nelle varie classi di collezioni, invece.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top