I was asked this question in interview and can’t find a solution to it:
I have declared a list in my class. During its declaration, I haven’t
made it static. But after adding some data to it, I want to make it
static. Is it possible?
We are allowed to change the data type of the list.
Edit: Is it not possible to declare an array of static type and then convert the list to array and hence make it static?
Not using standard java, but you actually can manipulate the running byte code using a library such as Javassist; technically the answer is “yes”, but you may be shot by the team leader if you actually do this.