Does Java have the ability to C # syntax equal
class MyClass{ private int[] array = new int[20]; public int this[int index] { get{ return array[i];}} //<-- array getter for object } MyClass test = new MyClass(); Console.WriteLine(test[0]);
(The code is just an example;))
Java does not support operator overloading, including the array subscript operator ( [] ).
[]
No, you cannot override / overload operators - Java does not support this. However, you can add a get method like:
class MyClass{ private int[] array = new int[20]; public int get(int i) { return array[i]; } }