You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Conor MacNeill <co...@m64.com> on 2000/07/08 14:33:08 UTC

JDK version checking

This is a minor curiosity.

I noticed that a lot of code is checking the JDK version with code like
	project.getJavaVersion() == Project.JAVA_1_1

This is an identity test as opposed to an equality test. Since the objects
involved are Strings, my instinctive reaction is to change these tests to
.equals() but in this case an identity test is actually OK.

Thoughts?

Conor



--
Conor MacNeill
Home: conor@m64.com
Work: conor@cortexebusiness.com.au
Web:  www.cortexebusiness.com.au


Re: JDK version checking

Posted by Fergus Gallagher <Fe...@OrbisUK.com>.
As a general rule you are right.  The first thing String.equals() does is 
the identity test so any performance loss is negligible.  After that it 
does a char by char comparison.

However, since Project.java assigns javaVersion to the fixed (static final) 
objects JAVA_1_x, there is no problem in this case.


At 22:33 08/07/00 +1000, you wrote:
>This is a minor curiosity.
>
>I noticed that a lot of code is checking the JDK version with code like
>         project.getJavaVersion() == Project.JAVA_1_1
>
>This is an identity test as opposed to an equality test. Since the objects
>involved are Strings, my instinctive reaction is to change these tests to
>.equals() but in this case an identity test is actually OK.
>
>Thoughts?
>
>Conor
>
>
>
>--
>Conor MacNeill
>Home: conor@m64.com
>Work: conor@cortexebusiness.com.au
>Web:  www.cortexebusiness.com.au

--
Fergus Gallagher
Orbis
http://www.orbisuk.com/
+44-(0)20-8987 0717