We have already seen in the Standard MBean section that attribute names cannot
be overloaded, that is, there cannot be two setters or getter and setter
pair for the same name that operates on different types. Let us see this with
some examples.
Consider a simple MBean implementation class Server which implements the interface
ServerMBean.
Case 1
Two setters overloaded:
public class Server
implements ServerMBean
{
.......
public void setState(int state)
{
// implementation of setState
}
public void setState(boolean flag)
{
// implementation of setState
}
}
For the above case, we have two overloaded setter methods. It is not possible
to determine whether the attribute State is of type int or boolean. Hence,
the above class is not a valid MBean.
Case 2
A getter and setter pair for the same name operating on different types:
public class Server
implements ServerMBean
{
.......
public int getState()
{
// implementation of getState
}
public void setState(boolean flag)
{
// implementation of setState
}
}
For the above case, it is not possible to determine whether State is a readOnly
attribute of type int or a writeOnly attribute of type boolean. Hence, the
above class is not a valid MBean.
Special Cases
Also possible are the below cases which are valid.
Case 1
public class Server
implements ServerMBean
{
.......
public void setState(int state)
{
// implementation of setState
}
public void setState(boolean flag, int state)
{
// implementation of setState
}
}
For the above case, State is a attribute of type int. The setState method
that takes two arguments will be exposed as one of the operations.
Case 2
public class Server
implements ServerMBean
{
.......
public int getState()
{
// implementation of getState
}
public int getState(boolean flag)
{
// implementation of getState
}
}
For the above case, State is an attribute of type int. The getState method
that takes a boolean argument will be exposed as one of the operations.