About Question enthuware.ocpjp.v7.2.1401 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
doziransky
Posts: 8
Joined: Wed Mar 16, 2016 10:57 am
Contact:

About Question enthuware.ocpjp.v7.2.1401 :

Post by doziransky »

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.

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1401 :

Post by admin »

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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests