AngularJS在其文档中明确指出服务是单身人士:
AngularJS services are singletons
Run Code Online (Sandbox Code Playgroud)
与直觉相反,module.factory也返回一个Singleton实例.
鉴于非单例服务有很多用例,实现工厂方法返回服务实例的最佳方法是什么,这样每次ExampleService声明一个依赖项时,它都会被一个不同的实例所满足ExampleService?
我正在寻找一个好的Java BitSet示例来使用0和1.我试着查看Javadocs,但是我只是通过阅读来了解该类的用法.例如,会如何and,or以及xor方法在两个不同的工作BitSet对象?
例如:
BitSet bits1 = new BitSet();
BitSet bits2 = new BitSet();
bits2.set(1000001);
bits1.set(1111111);
bits2.and(bits1);
System.out.println(bits2);
Run Code Online (Sandbox Code Playgroud)
如果我这样做,它返回bits2为空为什么是这样?
我以标准的方式在Java中使用断言,在我的IDE中打开它们.所以他们不是生产发布的一部分.最近我一直在看代码示例,throw new AssertionError()我开始考虑AssertionError应该使用的情况而不是断言.
我的猜测主要区别在于断言的可选性,因此它们不会降低生产性能,因此它们可以在代码中经常出现,但修复用户报告的难以再现的错误则更难.
因为AssertionError,恰恰相反.
我还发现AssertionError在执行不应该得到的代码中更实用,而不是使用assert false //We should not be here.特别是如果需要返回值.例如:
int getFoo(AnEnum a){
if (a == AnEnum.ONE)
return bar();
else if (a == AnEnum.TWO)
return SOME_VALUE;
//else
assert false; //throw new AssertionError();
return -1; //not necessary when usin AssertionError
}
Run Code Online (Sandbox Code Playgroud)
AssertionError- 应该提供还是仅仅是Error(和断言类型)的事实足以或多或少地确定在发现错误的情况下将提供堆栈跟踪?元素必须具有"字符串列表"类型,并且可以存在0或更多地出现该类型的信息.所以我做的是:
<xs:element name="xxx" type="ooo" />
<xs:simpleType name="ooo">
<xs:list itemType="xs:string" />
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud)
我相信这是正确的,但是
我在哪里放minOccur,并maxOccur在这里?
在我的Android应用程序中,我运行一个计时器并在其他一些事件上取消它:
class MyTimerTask extends TimerTask {
override boolean cancel() {
...
}
override void run() {
...
}
}
...
Timer t = new Timer();
t.schedule(new MyTimerTask(),...)
...
t.cancel();
Run Code Online (Sandbox Code Playgroud)
我期待t.cancel()能够自动调用MyTimerTask的cancel()方法.但是从不调用该方法.
我想知道这两种方法之间究竟有什么不同,以及为什么第二种方法不能自动调用.
我在使用下划线去抖的服务中有一个方法.
在该方法内部是对不同服务的方法的调用.我正在尝试测试调用不同的服务.
在我尝试测试debounced方法时,从不调用不同服务的方法,并且jasmine失败:
"期待的间谍aMethod被称为."
我知道它被调用(它以chrome格式登录到控制台),它只是在预期已经失败后被调用.
因此...(最好)不添加Sinon或其他依赖项并且
给予解决方案的奖励积分*不必将_.debounce转换为$ timeout ...
怎么办?
angular.module('derp', [])
.service('herp', function(){
return {
aMethod: function(){
console.log('called!');
return 'blown';
}
};
})
.service('Whoa', ['herp', function(herp){
function Whoa(){
var that = this;
this.mindStatus = 'meh';
this.getMind = _.debounce(function(){
that.mindStatus = herp.aMethod();
}, 300);
}
return Whoa;
}]);
Run Code Online (Sandbox Code Playgroud)
describe('Whoa', function(){
var $injector, whoa, herp;
beforeEach(function(){
module('derp');
inject(function(_$injector_){
var Whoa;
$injector = _$injector_;
Whoa = $injector.get('Whoa');
herp = $injector.get('herp');
whoa = new Whoa();
});
});
beforeEach(function(){
spyOn(herp, 'aMethod').andCallThrough();
});
it('has …Run Code Online (Sandbox Code Playgroud) 我在tomcat服务器中收到此错误.
Exception in thread "http-bio-8080-exec-17"
Exception in thread "http-bio-8080-exec-2"
Exception in thread "http-bio-8080-exec-15"
Exception in thread "http-bio-8080-exec-20"
Exception in thread "http-bio-8080-exec-18"
java.lang.OutOfMemoryError: Java heap space.
Run Code Online (Sandbox Code Playgroud)
我见过MAT但是如何.hprof在Tomcat服务器中生成文件.
谢谢.
Date对象初始化我遇到了一个奇怪的问题.并想知道是否有人可以解释为什么..
var exp1 = new Date('2014-10-17');
var exp2 = new Date(2014,9,17);
var exp3 = new Date('17 Oct 2014');
console.log(exp1);
console.log(exp2);
console.log(exp3);
Run Code Online (Sandbox Code Playgroud)
结果:
Thu Oct 16 2014 18:00:00 GMT-0600 (MDT) // 16th? Fri Oct 17 2014 00:00:00 GMT-0700 (MST) // Why GMT -7 Fri Oct 17 2014 00:00:00 GMT-0600 (MDT) // The only one that works as expected
为什么这三个Date对象如此不同?
1)为什么不允许以下任务:
byte b = 0b11111111; // 8 bits or 1 byte
Run Code Online (Sandbox Code Playgroud)
但是这个任务是允许的:
int i = 0b11111111111111111111111111111111; //32 bits or 4 bytes
Run Code Online (Sandbox Code Playgroud)
两种类型都是签名的,我希望b并且i是-1.
2)为什么整数MIN_VALUE没有符号?
public static final int MIN_VALUE = 0x80000000;
Run Code Online (Sandbox Code Playgroud)
但字节MIN_VALUE确实有一个标志?
public static final byte MIN_VALUE = -128;
Run Code Online (Sandbox Code Playgroud) 考虑使用s URLClassLoader集合进行参数化,URL这是扩展目录和jar文件的混合.例如:
URL[] urls = new URL[] {
new URL("file:/D:/work/temp/jars/spring-security-core-3.2.0.RELEASE.jar"),
new URL("file:/D:/work/temp/jars/spring-security-config-3.2.0.RELEASE.jar"),
...
new URL("file:/D:/work/temp/domain/bin/"),
new URL("file:/D:/work/temp/web/bin/"),
...
}
URLClassLoader cl = new URLClassLoader(urls);
Run Code Online (Sandbox Code Playgroud)
类加载器正确处理getResources()位于包内某处的资源请求"org/my/package/conf.properties".通过正确处理我的意思是类加载器成功找到目录和jar中的所有匹配项.
传入的特殊空字符串名称getResources("")应该产生所有可用根的URL(在目录和jar中).然而,在ClassLoaders中存在已知的限制,其导致仅返回对应于目录的根.所有根罐子都被丢弃了.
使用classloader.getURLs[]而不是classloader.getResources("")不能与我合作,因为我有一个相互依赖的URLClassLoaders 的复杂图形,所以结果将完全不同.此外,我的类加载器将被第三方类路径扫描设施使用,该设施使用getResources("")调用来设置内部搜索库.这样就无法找到位于罐子里的资源.
我目前有一个工作修复,我扩展URLClassLoader并手动处理带有空字符串的请求,除了返回URLs 的返回集合中的目录之外,还强制执行jar的根.
不过我的问题是:
这种限制的概念/技术原因是什么(不返回罐子的路径)?
通过手动修复,我是否违反任何重要合同?
有没有很好的方法来获得理想的行为?
感谢您的任何想法!