Frage

Ich habe eine Seite hier geschrieben auf Arrays als geeignete Objekte mit ihren eigenen Methoden, anstatt sich auf Hilfsklassen wie Arrays, Arrays und ArrayUtils verwenden.

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

Ich bin sicher, ich bin nicht der erste mit dieser Idee, aber ich habe Probleme für andere Benutzer hatte die darüber geschrieben haben, bevor.

Kann jemand mir helfen mit einigen Referenzen zu diesem Thema?

Können Sie Kommentare hinzufügen, wenn Sie einen Verweis auf, warum dies eine schlechte Idee, oder eine gute Idee, wenn Sie eine haben?

Link gelöscht. Hinzufügen Hauptpunkte

Dies ergibt sich aus der Idee der Projekt Münze

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.

Treat Array als Objekte mit ihren eigenen Methoden, anstatt Werte Helfer Methoden übergeben werden. Dies führt zu einem natürlicheren Codierung und gibt den mehr Unmittelbarkeit Methoden. z.B. durch Code-Vervollständigung.

MAJOR ADVANTAGE: What makes the proposal a favorable change?

Es OO Programmierung Arrays bringen, unterstützt Methoden bereits verfügbar und geschrieben werden.

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

Objektorientiert Konsistenz für Arrays.

MAJOR DISADVANTAGE: There is always a cost.

Jemand hat es zu schreiben und testen Sie es.

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

Anrufhilfsmethoden.

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

ADVANCED. Beispiel: Zeigen nutzen Nutzen (n) des Merkmals

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.

Eine Klasse wie java.lang.Array müßte als Mutter aller Arrays hinzugefügt werden. Subklassen für bestimmtes int [], boolean [] auch erforderlich sein könnte. Die Grammatik sollte nicht dramatisch anders sein.

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!

In der eine neue übergeordnete bietet für Arrays verwendet werden könnte, würde die Zusammenstellung der gleiche sein, wie es jetzt ist. Es ist jedoch die JVM, die müssten akzeptieren, dass ein Array eine andere Superklasse hat.

TESTING: How can the feature be tested?

Überprüfen Sie die neuen Methoden die gleichen Dinge wie die Helfer Methoden tun. (Sollte einfach sein, wenn in der Tat nennen sie nur die gleichen Hilfsmethoden)

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

Dies sollte den rt.jar hinzugefügt wird

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.

Die Superklasse für einen Array müßte java.lang.Array oder dergleichen anstelle von java.lang.Object zurückzukehren. Aber auch hier kann dies eine Änderung für die JVM anstatt der rt.jar Code.

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.

Die Änderung der javadoc reflektiert werden soll.

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

Ersetzen Anrufe Arrays.xxx (array, args) array.xxx (args);

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

Anrufe zu hashCode () und equals () geändert werden würde, wenn jede Methode genommen wurde. Dies kann in dem Fall, dass diese Methoden nicht akzeptabel gelassen werden könnten, da sie eher als Aufruf Arrays.hashCode ist () oder 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?

Nein.

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

Dies ist, was ich für die Hilfe auf, Fehlermeldungen oder andere Referenzen suchen

War es hilfreich?

Lösung

Ich schlage vor, Sie die stattdessen verschiedenen Sammlungen suchen in Klassen.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top