Basically I want to create a data structure of values already known at compile time. In C I'd do it like this:
struct linetype { int id; char *descr; };
static struct linetype mylist[] = {
{ 1, "first" },
{ 2, "second" }
};
The only soultion I have found in Java involves creating the array at runtime:
public class Outer {
public class LineType {
int id;
String descr;
private LineType( int a, String b) {
this.id = a;
this.descr = b;
}
}
LineType[] myList = {
new LineType( 1, "first" ),
new LineType( 2, "second" ),
};
This appears cumbersome and ineffective (when the structures get long and complex). Is there another way?
(NB: please disregard any syntax errors as this is only sample code created for this question. Also, I am aware a String is somethign else than a character pointer pointing into the data segment. However, the argument works with primitive data types as well).