tag:blogger.com,1999:blog-3916529971656854151.post769817173294429911..comments2023-03-16T14:55:33.120+01:00Comments on Lasu 2 String: 'forget' keyword proposalLasu aka Marek Koziełhttp://www.blogger.com/profile/02386422649418906804noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-3916529971656854151.post-85124411041513022952009-12-20T15:23:42.336+01:002009-12-20T15:23:42.336+01:00@C.Karthik
Quite simple example can be done using ...@<b>C.Karthik</b><br />Quite simple example can be done using Streams.<br /><br /><b>final</b> InputStream is = ...;<br />...<br />is.close;<br /><b>forget</b> is; // Reason<br /><br />public void readContext(final InputStream is){<br /> ...<br /> <b>forget</b> is; // Reason<br /> ...<br />}<br /><br />Similar effect can be obtained using blocks to prevent further access. Any way, this is not always the solution, or it decrease code readability like when there are few variables and one of them need to be prevent from access, to do not damage data. <br /><br />{<br />InputStream is = null;<br /><b>try</b>{<br /> is = ...;<br /> ...<br /> }<br /><b>finally</b>{<br /> is.close;<br /> }<br />}<br />...<br /><br /><br />Mixing <b>final</b> with <b>forget</b> can make you to be sure that the variable contains one and the same object and after all operations will be done, there will be clear specification that it should be not accessed any more.<br /><br />When you back to such a code after <b>few months</b>, it can be a great advantage.Lasu aka Marek Koziełhttps://www.blogger.com/profile/02386422649418906804noreply@blogger.comtag:blogger.com,1999:blog-3916529971656854151.post-79312435827062406712009-12-18T15:12:00.020+01:002009-12-18T15:12:00.020+01:00Can you please explain with a real life exampleCan you please explain with a real life exampleC.Karthiknoreply@blogger.com