#AutoClosable and lists/hashmaps

1 messages · Page 1 of 1 (latest)

ashen mesa
#

Is AutoClosable.close() called when removing an item from a list? What about when the object is a key or a value in a HashMap?

smoky ploverBOT
#

<@&987246399047479336> please have a look, thanks.

smoky ploverBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

nova crown
ashen mesa
#

no, when the .remove() function is called does it call AutoClosable.close() before removing it from the list

#

for the object that is being removed

nova crown
ashen mesa
nova crown
ashen mesa
#

the list would know that since... it's being removed? I don't understand

#

if you remove an object from a list you most likely don't want it

nova crown
ashen mesa
#

oh i see

#

so the answer is no

#

thank you

nova crown
#

also note two things

#
  1. The code creating something that can be closed should be the one closing it, not the method the object is passed into, that's because of responsibilities : a piece of code should be responsible for what it did, and what it did only, not more, not less
  2. Methods shouldn't have side effects or anything that is not included in the name of the method, and so, a remove() method should only remove, it should never modify the removed object
    @ashen mesa
ashen mesa
#

thanks for this info

nova crown
ashen mesa
#

I understand, thanks