Difference between these two code snippets

Hi,

Can any one tell me the difference between the following two code snippets any specific advantage of using the first one.

I've a final boolean variable "readOnly" in the class. and the following method

private final void setReadOnlyPolicy(Connection c) throws SQLException {

boolean readOnlyPolicy = readOnly;

if (c.isReadOnly() != readOnlyPolicy) {

// read only policy of the connection is different than specified,

// change it

c.setReadOnly(readOnlyPolicy);

}

}

Cann't we write it like

private final void setReadOnlyPolicy(Connection c) throws SQLException {

if (c.isReadOnly() != readOnly) {

// read only policy of the connection is different than specified,

// change it

c.setReadOnly(readOnlyPolicy);

}

}

Regards,

Rakesh

[861 byte] By [rakesh_mscita] at [2007-11-27 8:30:51]
# 1
No difference. Both don't use [ code ] tags and I thus I don't feel like reading them.
CeciNEstPasUnProgrammeura at 2007-7-12 20:26:05 > top of Java-index,Java Essentials,Java Programming...
# 2
Anyway, I don't see a difference.
CeciNEstPasUnProgrammeura at 2007-7-12 20:26:05 > top of Java-index,Java Essentials,Java Programming...
# 3
In the second code snippet u are avoid local variable....'readOnlyPolicy' but in 'c.setReadOnly(readOnlyPolicy);'u r again using it....does this code works ?
EKTa at 2007-7-12 20:26:05 > top of Java-index,Java Essentials,Java Programming...
# 4
Sorry that was my mistake, forgot to change the method parameter.It'll be c.setReadOnly(readOnly);Thanks for the reply.Regards,Rakesh
rakesh_mscita at 2007-7-12 20:26:05 > top of Java-index,Java Essentials,Java Programming...