Basically, I want to create a data structure of values โโalready known at compile time. In C, I would do it like this:
struct linetype { int id; char *descr; }; static struct linetype mylist[] = { { 1, "first" }, { 2, "second" } };
The only thing I found in Java is creating an 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" ), };
It seems cumbersome and inefficient (when structures become long and complex). Is there another way?
(NB: please ignore any syntax errors, as this is just a sample code created for this question. Also, I know that String is somethign else than a pointer to a character pointing to a data segment. However, the argument works with primitive data types).
source share