What is the Attribute.getValue method in Java?
The Attribute class denotes an MBean attribute. The MBean server and other objects use this class to get and set the values of attributes. The Attribute class is present in the javax.management.Attribute package.
The getValue method can be used to get the value of the attribute object.
Syntax
public Object getValue()
This method doesn’t take any parameters.
The getValue method returns the value of the Arrtribute object.
Code
The code below demonstrates how to use the getValue method.
import javax.management.Attribute;class AttributeGetValueExample {public static void main( String args[] ) {Attribute attr = new Attribute("Website_Name", "Educative");System.out.println( "Attribute value is: " + attr.getValue());}}
Explanation
In the code above:
-
In line 1, we import the
Attributeclass. -
In line 4, we create an
Attributeobject with the nameattr. For this object, we set the attribute name asWebsite_Nameand the attribute value asEducative. -
In line 5, we call the
getValuemethod on theattrobject and print the returned value.