Migrating from Delphi to Java - enum types and set types

Hi!

I'm trying to use some Java types with similar behaviour with Delphi types.

One is enum type, that is used to choice one option from some available options. Here is an example in Delphi:

type Alignment = (LEFT, RIGHT);

var a: Alignment;

a := LEFT;

I'm trying to simulate the same behaviour with the following Java code:

<code>

public final class Alignment {

public static final Alignment LEFT = new Alignment('L');

public static final Alignment RIGHT = new Alignment('R');

private final char alignmentType;

private Alignment(char alignmentType) {

this.alignmentType = alignmentType;

}

}

</code>

Now i can use

Alignment a = Alignment.RIGHT;

Is it correct? Is there some easyest way?

Another Delphi type that i need to use in Java is set of types. These types are used you you need to select zero, one or many options from a set of options. Here is an example in Delphi:

<code>

type StringOptions = set of (tsfUpperCase, tsfNoAccent, tsfOnlyDigit);

var so: StringOptions;

so := [tsfUpperCase, tsfOnlyDigit];

</code>

I didn't found a way to represent this in Java. Is there a way to achieve this?

Thanks.

[1306 byte] By [fabianobonina] at [2007-10-2 17:48:19]
# 1

Are you using JDK 1.5? If yes, there is an 'enum' type that will almost certainly be what you are looking for. If not (JDK 1.4 or earlier) do a Google on 'Java type-safe enum example'. Specifically regarding the following:

Alignment a = Alignment.RIGHT

That is fine. But normally, you do not need to assign another variable. Just use Alignment.RIGHT directly.

- Saish

Saisha at 2007-7-13 19:06:19 > top of Java-index,Java Essentials,New To Java...