# Class PropertyBase<T,K>

java.lang.Object
com.codename1.properties.PropertyBase<T,K>

Direct Known Subclasses:
  `CollectionProperty, MapProperty, Property`

public class PropertyBase<T,K> extends java.lang.Object
Base class for property types

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `PropertyBase(String name)`
  All properties must have a name
  `protected`
  `PropertyBase(String name, java.lang.Class genericType)`
  All properties must have a name, a generic type is helpful

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addChangeListener(PropertyChangeListener<T,K> pl)`
  Fires a notification that a property value changed to the given listener
  `static void`
  `bindGlobalGetListener(PropertyChangeListener listener)`
  Binds an event callback for get calls and property reads
  `static void`
  `bindGlobalSetListener(PropertyChangeListener listener)`
  Binds an event callback for set calls and property mutation
  `boolean`
  `equals(java.lang.Object obj)`
  Compares this property to another property
  `protected void`
  `firePropertyChanged()`
  Delivers the property change event to listeners if applicable
  `java.lang.Object`
  `getClientProperty(String key)`
  Returns the client property set to this property name
  `java.lang.Class`
  `getGenericType()`
  Returns the generic type of this property if it is known or null
  `String`
  `getLabel()`
  The label of the property defaults to its name but can be changed to anything
  `String`
  `getName()`
  The property name is immutable and can't be changed after creation it should match the parent field name by convention
  `int`
  `hashCode()`
  `void`
  `putClientProperty(String key, java.lang.Object o)`
  Places a property that will apply statically to all instances of this property
  `void`
  `removeChangeListener(PropertyChangeListener<T,K> pl)`
  Removes the property change listener from the list of listeners
  `void`
  `setLabel(String label)`
  The label of the property defaults to its name but can be changed to anything, it can be used when binding a property to UI elements
  `void`
  `stopListening()`
  This method will work when invoked from a propertyChanged callback and should be similar to `removePropertyChangeListener(this)`.
  `String`
  `toString()`
  Default toString that provides easier debug information
  `protected final void`
  `validateCollectionType(java.lang.Class elementType)`
  Validates that the collection type is valid and throws an exception otherwise

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### PropertyBase

    protected PropertyBase(String name)

    All properties must have a name

    ###### Parameters

    - `name`: the name of the property

  - ### PropertyBase

    protected PropertyBase(String name, java.lang.Class genericType)

    All properties must have a name, a generic type is helpful

    ###### Parameters

    - `name`: the name of the property

    - `genericType`: the property type to workaround issues with erasure

- ## Method Details

  - ### bindGlobalSetListener

    public static void bindGlobalSetListener(PropertyChangeListener listener)

    Binds an event callback for set calls and property mutation

    ###### Parameters

    - `listener`: will be invoked whenever any mutable property is changed

    ###### Throws

    - `RuntimeException`: if a set listener is already bound, there can be only one per application

    ###### Deprecated

    Usage of this method isn't recommended, it's designed for internal use

  - ### bindGlobalGetListener

    public static void bindGlobalGetListener(PropertyChangeListener listener)

    Binds an event callback for get calls and property reads

    ###### Parameters

    - `listener`: will be invoked whenever any property is read

    ###### Throws

    - `RuntimeException`: if a get listener is already bound, there can be only one per application

    ###### Deprecated

    Usage of this method isn't recommended, it's designed for internal use

  - ### getName

    public String getName()

    The property name is immutable and can't be changed after creation it should match the parent field name by convention

    ###### Returns

    the property name;

  - ### firePropertyChanged

    protected void firePropertyChanged()
    Delivers the property change event to listeners if applicable

  - ### stopListening

    public void stopListening()
    This method will work when invoked from a propertyChanged callback and should be similar to `removePropertyChangeListener(this)`. It's useful for lambda's where `this` means the base class and not the listener so `removePropertyChangeListener(this)` won't do what we want unless we convert to an inner class

  - ### addChangeListener

    public void addChangeListener(PropertyChangeListener<T,K> pl)

    Fires a notification that a property value changed to the given listener

    ###### Parameters

    - `pl`: the listener

  - ### removeChangeListener

    public void removeChangeListener(PropertyChangeListener<T,K> pl)

    Removes the property change listener from the list of listeners

    ###### Parameters

    - `pl`: the change listener

  - ### putClientProperty

    public void putClientProperty(String key, java.lang.Object o)

    Places a property that will apply statically to all instances of this property

    ###### Parameters

    - `key`: the key to put

    - `o`: the value object

  - ### getClientProperty

    public java.lang.Object getClientProperty(String key)

    Returns the client property set to this property name

    ###### Parameters

    - `key`: the key of the property

    ###### Returns

    the value that was previously placed with put client property

  - ### equals

    public boolean equals(java.lang.Object obj)

    Compares this property to another property

    ###### Parameters

    - `obj`: the other property

    ###### Returns

    true if they are equal in name and value

    Overrides:
      `equals` in class `java.lang.Object`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `java.lang.Object`

  - ### toString

    public String toString()

    Default toString that provides easier debug information

    ###### Returns

    a formatted representation of the property for debugging

    Overrides:
      `toString` in class `java.lang.Object`

  - ### getGenericType

    public java.lang.Class getGenericType()

    Returns the generic type of this property if it is known or null

    ###### Returns

    the generic type

  - ### getLabel

    public String getLabel()

    The label of the property defaults to its name but can be changed to anything

    ###### Returns

    the label for the property

  - ### setLabel

    public void setLabel(String label)

    The label of the property defaults to its name but can be changed to anything, it can be used when binding a property to UI elements

    ###### Parameters

    - `label`: the new label value

  - ### validateCollectionType

    protected final void validateCollectionType(java.lang.Class elementType)

    Validates that the collection type is valid and throws an exception otherwise

    ###### Parameters

    - `elementType`: the generic type of the collection