I vaguely recall a question from an earlier test saying something about how a File object can never be changed once it is created.
So then how can renameTo(File newFile) work?
I'm assuming that it's similar to when you try to change a String, where you don't actually change the String but a new String is created and the reference is reassigned to that String.
About Question enthuware.ocpjp.v7.2.1401 :
Moderator: admin
-
- Posts: 8
- Joined: Wed Mar 16, 2016 10:57 am
- Contact:
-
- Site Admin
- Posts: 10043
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1401 :
That is correct. Instances of the File class are immutable but its methods can create new ones.
BTW, renameTo is not creating a new File instance. It is just renaming the physical file name. The original File object remains unchanged. You should try it out.
-Paul.
BTW, renameTo is not creating a new File instance. It is just renaming the physical file name. The original File object remains unchanged. You should try it out.
-Paul.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 32 guests