我在这里编写了一个页面,将数组作为适当的对象使用自己的方法,而不是依赖于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编程,支持已经可用和已编写的方法。
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.Array等而不是java.lang.Object。但是,这可能是对JVM而不是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.
更改应反映在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.
这就是我正在寻求帮助,错误报告或其他参考资料
答案 0 :(得分:3)
我建议您查看各种集合类。