高度重复的代码通常是一件坏事,并且有一些设计模式可以帮助减少这种情况.然而,由于语言本身的限制,有时它是不可避免的.以下示例来自java.util.Arrays:
/**
* Assigns the specified long value to each element of the specified
* range of the specified array of longs. The range to be filled
* extends from index <tt>fromIndex</tt>, inclusive, to index
* <tt>toIndex</tt>, exclusive. (If <tt>fromIndex==toIndex</tt>, the
* range to be filled is empty.)
*
* @param a the array to be filled
* @param fromIndex the index of the first element (inclusive) to be
* filled with the specified value
* @param toIndex …Run Code Online (Sandbox Code Playgroud)