Re: EnumSet + contains: strange behavior




"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

.