Safeguarding method parameters in java -


i want safe guard method parameters passed called method being changed accidentally. know can use final keyword achieve (partially) following in method signature.

public void somemethod(final int intval, final myclass myobj){} 

with of above signature cannot change value of intval, can change values (members) of myobj (i can safe guard reference not being changed, not members of referencing object, why said partial).

now looking safe guard myobj members either, getting changed in called method somemethod.

in knowledge achieve using following ways

  1. create immutable class , pass parameter
  2. deep copy object , send cloned object method.

is there better apporach safeguard method parameters?


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -