attr.java

来自「JAVA的例子程序」· Java 代码 · 共 58 行

JAVA
58
字号
//package a;
/**
 *An <code>Attr</code> object defines an attribute as a 
 *name /value pair ,where the name is a <code> String </code>
 *and the value an arbitrary <code> Object </code>.
 *
 *@since &lt &#064 2.0 &gt
 *
 */
public  class Attr{
    /** The attribute name.  */
    private final String name;
    /** The attribute value.*/
    private Object value=null;
    /**
     *Creates a new attribute with the given name and an
     *initial value of <code>null</code>.
     *@see Attr#Attr(String,Object)
     */
     public Attr(String name){
        this.name=name;
        }
     /**
      *Creates a new attribute with the given name and 
      *initial value.
      *@see Attr#Attr(String)
      */
     public Attr(String name,Object value){
        this.name=name;
        this.value=value;
        }
     /**Returns this attribute's name.*/
     public String getName(){
        return name;
        }
     /**Returns this attribute's value.*/
     public Object getValue(){
        return value;
        }
     /**
      *Set the value of this attribute. Changes the 
      *value returned by calls to {@link #getValue}.
      *@param newValue The new value for the attribute.
      *@return The original value.
      *@see #getValue
      */
    public Object setValue(Object newValue){
        Object oldVal=value;
        value=newValue;
        return oldVal;
        }
    /**
     *Returns a String of the from <code>name=value</code>.
     */
     public String toString(){
        return name+"='"+value+"'";
        }
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?