Re: swap method in Java
From: Chris Smith (cdsmith_at_twu.net)
Date: 06/23/04
- Next message: Jezuch: "Re: swap method in Java"
- Previous message: Roedy Green: "Re: Simplest way of doing DB connection pooling. WAS Best practice for initializing JDBC connection in Servlets."
- In reply to:(deleted message) Stefan Ram: "Re: swap method in Java"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 22 Jun 2004 16:33:50 -0600
Stefan Ram wrote:
> When is it not applicable to swap the variable names in
> the rest of the block? I.e.,
>
> class Swap4a
> { final static int x=5, y=7 ;
> public static void main( final String[] args )
> { System.out.println( "x now is " + y + " y now is " + x ); }}
Generally speaking, when:
a) the swaps occur in a loop or conditional, or
b) the variables being swapped are not local (for example, they are
fields of an object or elements of an array), unless you can prove that
the data will only be accessed in controlled in a local environment.
c) the variables are fields of an array (even under the local exception
above), and you plan to access them in a loop. Or, on a related but
less common note, the variables are fields and you plan to access them
using reflection.
-- www.designacourse.com The Easiest Way to Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation
- Next message: Jezuch: "Re: swap method in Java"
- Previous message: Roedy Green: "Re: Simplest way of doing DB connection pooling. WAS Best practice for initializing JDBC connection in Servlets."
- In reply to:(deleted message) Stefan Ram: "Re: swap method in Java"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|