Efo*_*ren 9 java arrays class accessor
使用Java,有没有办法制作一个可以像数组一样使用[]访问器的自定义类?
正常数组
int[] foo = int[5];
foo[4] = 5;
print(foo[4]);
//Output: "5"
Run Code Online (Sandbox Code Playgroud)
自定义类
class Bar {
//Custom class that uses index as a ref
}
Bar foo = new Bar(5);
foo.set(4, 5);
print(foo[4]);
//Output: "5"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
261 次 |
| 最近记录: |