Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Assume the following scenario. i call a method like this
String[] arr = {"1","2","3"}; method(arr);
and the method signature is
public void method(Object o) { // how will i get back the String[] arr object now.. }
The casting would look like this:
final String[] array = (String[]) o;
Add a comment
If you are writing
public void method(Object o) { String[] arr = (String[]) o; }
this means the only valid parameter type is String[] and you are better off making this clear with
public void method(String[] arr) { }
Just cast it back.
String[] o2 = (String[]) o;
Here o is your passed String[] object. Just cast it to String[]. And if you are planning to pass an array every time then change your method signature to:
o
String[]
public void method(Object[] o)
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.