小编The*_*orm的帖子

Arrays.setAll不能使用布尔值

我想创建一个大数组,并想尝试一些lambda,但由于某种原因:

cells = new boolean[this.collums][this.rows];
IntStream.range(0, cells.length).forEach(x -> Arrays.setAll(cells[x], e -> MathX.fastNextInt(1) == 0 ? true : false));
Run Code Online (Sandbox Code Playgroud)

不会工作,即使这样:

cells = new boolean[this.collums][this.rows];
IntStream.range(0, cells.length).forEach(x -> Arrays.setAll(cells[x], e -> true));
Run Code Online (Sandbox Code Playgroud)

不适用.

编译器错误是:

类型不匹配:无法从布尔值转换为T.

和:

Arrays类型中的方法setAll(T [],IntFunction)不适用于参数(boolean [],(e) - > {})

java arrays lambda boolean java-8

4
推荐指数
1
解决办法
172
查看次数

geoJSON onEachFeature 鼠标事件

我在尝试将 onEachFeature Methode 用于 geoJSON 层时遇到问题。我尝试为每个功能分配一个点击侦听器。问题是,当我单击某个功能时,总是会收到该错误:

未捕获的类型错误:无法读取未定义的属性“detectChanges”

我可以想到这是因为在构造函数运行之前分配了层,但是在 ngOnInit 函数中这样做也不起作用。如果有一个很好的方法来做到这一点会很酷:)

  constructor(private changeDetector: ChangeDetectorRef){}

  fitBounds: LatLngBounds;
  geoLayer = geoJSON(statesData, {onEachFeature : this.onEachFeature});

  onEachFeature(feature , layer) {
    layer.on('click', <LeafletMouseEvent> (e) => {
        this.fitBounds = [
            [0.712, -74.227],
            [0.774, -74.125]
        ];
        this.changeDetector.detectChanges();
    });
  }
Run Code Online (Sandbox Code Playgroud)

  layer: Layer[] = [];
  fitBounds: LatLngBounds;
  
  onEachFeature(feature , layer : geoJSON) {
    layer.on('click', <LeafletMouseEvent> (e) => {
        console.log("tets"+e.target.getBounds().toBBoxString());
        this.fitBounds = [
            [0.712, -74.227],
            [0.774, -74.125]
        ];
        this.changeDetector.detectChanges();
    });
  }
  
constructor(private changeDetector: ChangeDetectorRef){}

ngOnInit() {
      let geoLayer = geoJSON(statesData, {onEachFeature …
Run Code Online (Sandbox Code Playgroud)

leaflet ngx-leaflet angular5

1
推荐指数
1
解决办法
990
查看次数

标签 统计

angular5 ×1

arrays ×1

boolean ×1

java ×1

java-8 ×1

lambda ×1

leaflet ×1

ngx-leaflet ×1