PDA

View Full Version : [java] access to member in composition


mickey
21st June 2008, 14:45
//a.class
public class A {
private static enum Day { Sun, Mon, Tue }
private B b;
public A (B cb) { b = cb; }
friend B; //exists??
}
//b.class
public class B {
public B () { }
private int DoSomething () {
// here I have to acces to enum Day like switch (Day) ; but from here
}
}

Does it exists a keyword like "friend" to do this? Or Anyone can suggest me anything better!?

Furthermore: is it possibile something like C ? (= 0 I mean)

private static enum Day { Sun=0, Mon=1, Tue=2 }

thanks

marcel
21st June 2008, 23:19
Java doesn't have the "friend" concept. In Java you have the option of nested classes or private, file scope classes.

You can use either of them, from what I see you're trying to do.

marcel
21st June 2008, 23:24
Here's a nice thread that goes into the more "philosophical" aspects of this issue: http://forum.java.sun.com/thread.jspa?threadID=499151&messageID=2358324