Is there a way to make a custom class that can have [] used on it in Java, similar to an array?
accessor, arrays, class, java
Solution
No, you cannot overload `[]` operator for your classes in `Java`. But you can create getter for your array.
Problem
With Java, is there a way to make a custom class that can have the [] accessor used on it like an array? Normal array ``` int[] foo = int[5]; foo[4] = 5; print(foo[4]); //Output: "5" ``` Custom Class ``` class Bar { //Custom class that uses index as a ref } Bar foo = new Bar(5); foo.set(4, 5); print(foo[4]); //Output: "5" ```