Re: how to set a state
mike wrote:
Hi,
I am using a class called session that contains a has an internal
state object. However I can only do get on the state.
This is the code I need to test but since I cannot set the sate since
Session is an external interface with an innner class called State. Is
there a way around this for me?
cheers,
//mikael
switch (session.getState()) {
case TERMINATED:
//Do something
break;
case EARLY:
//do something
break;
case CONFIRMED:
//do something
break;
case INITIAL:
//do something
break;
}
}
In the first place, what is the point of this code fragment? You don't
provide the code for Session, you don't provide the code for State, and you
don't provide the code for State's enclosing class. What are we supposed to
do, read your mind? Instead you provide a snippet that tells us nothing
relevant to your question. We can't even tell from this or your other post on
this code whether getState() returns an enum or an int. Come on, dude.
<http://sscce.org/>
As to your question, if Session is an "external" (what does that mean?)
interface, then it cannot have any inner classes.
<http://java.sun.com/docs/books/jls/third_edition/html/interfaces.html#9.5>
Interfaces may contain member type declarations (?8.5).
A member type declaration in an interface is implicitly static and public.
<http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.5.2>
The static keyword may modify the declaration of a member type C
within the body of a non-inner class T.
Its effect is to declare that C is not an inner class.
<http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.1.3>
An inner class is a nested class that is not
explicitly or implicitly declared static.
Next, what *does* set the State? It's got to come from somewhere. Where? How?
Answer our questions that we may answer yours.
<http://sscce.org/>
--
Lew