How do I Statically initialize an array of objects in Java? A simple example of my intentions follows:
Say my object is
public class FRIEND {
String name;
String phone;
}
My intent is to do something like the below which doesn't work (I've tried variations with no luck).
static FRIEND[] MyFriends[] = {
{ "Bob", "5551234" },
{ "Jack", "5716666" },
{ "Mary", "5341111" }
};
I'e found tons of examples of array initialization but they either (a) initialize arrays of primitives (e.g. int[]) or (b) use loops with explicit setting (e.g., MyFriends[n].name = "Bob");
What am I doing wrong?
new FRIEND(...)in your array initialization.