code: public void setTypedVariable(final String name, final Class<?> type,
              final Object value, final Modifiers modifiers)
              throws UtilEvalError {
          // Setting a typed variable is always a local operation.
          final Variable existing = this.getVariableImpl(name,
                  false/* recurse */);
          // Null value is just a declaration
          // Note: we might want to keep any existing value here instead of reset
          // does the variable already exist? Is it typed?
          if (existing != null && existing.getType() != null)
              // If it had a different type throw error.
              // This allows declaring the same var again, but not with
              // a different (even if assignable) type.
              if (existing.getType() != type)
                  throw new UtilEvalError("Typed variable: " + name
                          + " was previously declared with type: "
                          + existing.getType());
              else {
                  if (existing.modifiers == null)
                      existing.modifiers = modifiers;
                  // else set it and return
                  existing.setValue(value, Variable.DECLARATION);
                  return;
              }
          // Add the new typed var
          this.variables.put(name,
                  this.createVariable(name, type, value, modifiers));
      }
docs: Declare a variable in the local scope and set its initial value. Value
  may be null to indicate that we would like the default value for the
  variable type. (e.g. 0 for integer types, null for object types). An
  existing typed variable may only be set to the same type. If an untyped
  variable of the same name exists it will be overridden with the new typed
  var. The set will perform a Types.getAssignableForm() on the value if
  necessary.
  <p>
  Note: this method is primarily intended for use internally. If you use
  this method outside of the bsh package and wish to set variables with
  primitive values you will have to wrap them using bsh.Primitive.
  @param name the name
  @param type the type
  @param value If value is null, you'll get the default value for the type
  @param modifiers may be null
  @throws UtilEvalError the util eval error
  @see bsh.Primitive