小编zyn*_*ick的帖子

"偏移或计数可能接近-1 >>> 1." 这是什么意思

在java String 源代码中,以下注释中注明的地方很少:

// Note: offset or count might be near -1>>>1.
Run Code Online (Sandbox Code Playgroud)

请考虑以下示例:

public String(char value[], int offset, int count) {
    if (offset < 0) {
        throw new StringIndexOutOfBoundsException(offset);
    }
    if (count < 0) {
        throw new StringIndexOutOfBoundsException(count);
    }
    // Note: offset or count might be near -1>>>1.
    if (offset > value.length - count) {
        throw new StringIndexOutOfBoundsException(offset + count);
    }
    this.offset = 0;
    this.count = count;
    this.value = Arrays.copyOfRange(value, offset, offset+count);
}
Run Code Online (Sandbox Code Playgroud)

正如我们所看到的,offset,value.length和count …

java

19
推荐指数
2
解决办法
393
查看次数

创建自定义Emberjs服务错误:尝试注入未知注入:`service:titleService`

我遇到了上面的错误:尝试注入未知的注入:service:titleService使用以下代码:

// initializers/titleService
export default {
  name: 'titleService',
  initialize: function(container, application) {
    application.inject('route', 'titleService', 'service:titleService');
  }
};

// services/titleService.js
import Ember from 'ember';
export default Ember.Service.extend({
  title(name) {
    this.set('title', name);
  }
});

// routes/login.js
import Ember from 'ember';
export default Ember.Route.extend({
  titleService: Ember.inject.service(),
  actions: {
    didTransition: function() {
      this.set('titleService.title', 'Login Page');
    }
  }
});

// templates/application.hbs
<div class="page-header">
   <h1>{{titleService.title}}</h1>
</div>
{{outlet}}
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

ember.js ember-cli

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

标签 统计

ember-cli ×1

ember.js ×1

java ×1