Re: EnumSet + contains: strange behavior
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Wed, 31 May 2006 15:34:12 GMT
"Ulrich Scholz" <d4@xxxxxxxxxxx> wrote in message news:1149087937.551514.198980@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Dear all,
The following example of EnumTest seems to be inconsitent with the
interface definition of contains: It executes the lines marked with
XXX, which clearly is an error. Does anyone have an explanation?
Thank you,
Ulrich
import java.util.*;
public class EnumSetTest
{
public enum EnumTest
{
ONE,
TWO,
}
public final void testEnumSet()
{
final EnumSet<EnumTest> result = EnumSet.noneOf(EnumTest.class);
if(result.isEmpty())
{
System.out.println("empty"); // enters this branch: correct
}
else
{
System.out.println("not empty");
}
if(result.contains(EnumTest.ONE));
{
System.out.println("error"); // XXX
}
if(result.contains(EnumTest.TWO));
{
System.out.println("error"); // XXX
}
}
}
There are semicolons after the if statement. Get rid of them.
- Oliver
.
- Follow-Ups:
- Re: EnumSet + contains: strange behavior
- From: Thomas Hawtin
- Re: EnumSet + contains: strange behavior
- From: Ulrich Scholz
- Re: EnumSet + contains: strange behavior
- References:
- EnumSet + contains: strange behavior
- From: Ulrich Scholz
- EnumSet + contains: strange behavior
- Prev by Date: Re: SoftReference operation synchronization detail
- Next by Date: Re: EnumSet + contains: strange behavior
- Previous by thread: EnumSet + contains: strange behavior
- Next by thread: Re: EnumSet + contains: strange behavior
- Index(es):