Arrays、Arrays、ArrayUtils などのヘルパー クラスに依存する代わりに、配列を独自のメソッドを持つ適切なオブジェクトとして使用する方法についてのページをここに書きました。
ints.sort(); // instead of Arrays.sort(ints);
// instead of int[] onemore = ArrayUtils.add(ints, 8);
int[] onemore = ints.add(8);
このアイデアは私が初めてではないと確信していますが、以前にこれについて書いた他の人を探すのに苦労しました.
このトピックに関する参考文献を教えてくれる人はいますか?
なぜこれが悪いアイデアなのか、または良いアイデアがあるのか についての参照がある場合は、コメントを追加できますか?
リンクを削除しました。要点追加
これは、Project 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.
ヘルパー メソッドに値を渡すのではなく、配列を独自のメソッドを持つオブジェクトとして扱います。これにより、より自然なコーディングが可能になり、メソッドの即時性が高まります。たとえば、コード補完を通じて。
MAJOR ADVANTAGE: What makes the proposal a favorable change?
OO プログラミングを array にもたらし、すでに利用可能で書かれたメソッドをサポートします。
MAJOR BENEFIT: Why is the platform better if the proposal is adopted?
配列のオブジェクト指向の一貫性。
MAJOR DISADVANTAGE: There is always a cost.
誰かがそれを書いてテストしなければなりません。
ALTERNATIVES: Can the benefits and advantages be had some way without a language change?
ヘルパー メソッドを呼び出します。
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 (....)
高度な例: 機能の高度な使用法を示します。
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.
すべての配列の親として java.lang.Array などのクラスを追加する必要があります。特定の int[]、boolean[] のサブクラスも必要になる場合があります。文法は劇的に異なるべきではありません。
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!
配列の新しい親を使用できる提供では、コンパイルは現在と同じになります。ただし、配列が異なるスーパークラスを持つことを受け入れる必要があるのは JVM です。
TESTING: How can the feature be tested?
新しいメソッドがヘルパー メソッドと同じことを行うことを確認します。(実際に同じヘルパーメソッドを呼び出すだけであれば、単純なはずです)
LIBRARY SUPPORT: Are any supporting libraries needed for the feature?
これは 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.
配列のスーパー クラスは、java.lang.Object の代わりに java.lang.Array などを返す必要があります。ただし、これも rt.jar コードではなく JVM の変更である可能性があります。
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.
変更は javadoc に反映されます。
MIGRATION: Sketch how a code base could be converted, manually or automatically, to use the new feature.
Arrays.xxx(array, args) の呼び出しを array.xxx(args); に置き換えます。
COMPATIBILITY
BREAKING CHANGES: Are any previously valid programs now invalid? If so, list one.
すべてのメソッドが使用された場合、hashCode() および equals() の呼び出しが変更されます。Arrays.hashCode() または 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?
いいえ。
REFERENCES
EXISTING BUGS: Please include a list of any existing Sun bug ids related to this proposal.
これは、ヘルプ、バグレポート、またはその他の参照を探しているものです