在ArrayList和Set中存储空值

时间:2017-06-05 18:10:17

标签: arraylist set

class Employee
{
  int id;

  Employee(int id)
  {
    this.id = id;
  }

  public int getID()
  {   
    return id;
  }

  public void displayID()
  {
    System.out.println("ID="+id);
  }
}

public class Example
{
  public static void main(String[] args)
  {

    Employee employee1 = new Employee(100);
    Employee employee3 = null;

    List<Employee> arrayListEx = new ArrayList<Employee>();
    Set<Employee> setEx = new HashSet<Employee>();

    arrayListEx.add(employee1);
    arrayListEx.add(employee3);
    setEx.add(employee1);
    setEx.add(employee3);

  }
}

友 根据我的理解,Set不应该允许将null值添加到它。 上面的代码片段是否应该为“setEx.add(employee3)”抛出编译时错误? 请指教,提前致谢。

1 个答案:

答案 0 :(得分:0)

来自Java Hashset文档:“此类允许null元素”。该文件将编译。

您提到您认为def make_model(features, layer_name="block2_conv1"): vgg = VGG16(include_top=False) layer = vgg.get_layer(layer_name) x = layer.output num_chars, char_w, char_h, char_filters = features.shape filters = features.transpose((1, 2, 3, 0)).astype(int) filters = filters / np.sqrt(np.sum(np.square(filters), axis=(0, 1), keepdims=True)) x = BatchNormalization()(x) specialized_layer = Conv2D(num_chars, (char_w, char_h)) x = specialized_layer(x) biases = np.zeros((num_chars, )) specialized_layer.set_weights([filters, biases]) model = Model(inputs=vgg.input, outputs=x) return model 不允许空值。这取决于其实施(link to docs