About Question enthuware.ocpjp.v8.2.1312 :

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

Moderator: admin

Post Reply
nikitos
Posts: 21
Joined: Mon Oct 24, 2016 6:55 am
Contact:

About Question enthuware.ocpjp.v8.2.1312 :

Post by nikitos »

I think that objects wrapped by this class are not thread-safe
If
1 in constructor copy input parameter to the obj
2 in getObject method returns copy of the obj
=> it will be thread-safe

Am I right?

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

Re: About Question enthuware.ocpjp.v8.2.1312 :

Post by admin »

No, that is not correct.
1. Because even if you return a copy of the object in getObject, a reference of this object that was passed to setObject already exists outside this class.
2. You dont know whether the clone is a deep clone or a shallow clone. It depends on how the class of the wrapped object is written.
If you like our products and services, please help us by posting your review here.

danidark9312
Posts: 4
Joined: Tue Jul 10, 2018 5:28 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1312 :

Post by danidark9312 »

This class will not even compile, because it has a final field that is not initialized, compile error will be shown, isn't this correct ?
untitled.png
untitled.png (25.78 KiB) Viewed 2063 times

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

Re: About Question enthuware.ocpjp.v8.2.1312 :

Post by admin »

What happened when you actually tried to compile it?
If you like our products and services, please help us by posting your review here.

__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1312 :

Post by __JJ__ »

Ha ha yes.
final fields do not need to be initialized with a value at the same time that they are declared; they can be initialized in either an IIB or a constructor.

jbilkes
Posts: 21
Joined: Tue Sep 09, 2014 3:28 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1312 :

Post by jbilkes »

If the constructor was a method, setObject or something, this class would be thread-unsafe right? since a calling class could insert and get it right after thinking it would get that object while another thread could called the setter in the period between these 2 actions.

To put it differently, would you call a class with only getters and setters thread-unsafe?

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

Re: About Question enthuware.ocpjp.v8.2.1312 :

Post by admin »

Correct, assuming the setter does not use any synchronization mechanism, it would be thread unsafe.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot], marpiva and 28 guests