从JDK 7开始,我一直很乐意使用它引入的方法来拒绝null
传递给不能接受它们的方法的值:
private void someMethod(SomeType pointer, SomeType anotherPointer) {
Objects.requireNonNull(pointer, "pointer cannot be null!");
Objects.requireNonNull(anotherPointer, "anotherPointer cannot be null!");
// Rest of method
}
Run Code Online (Sandbox Code Playgroud)
我认为这种方法可以使代码非常整齐,易于阅读,我正在努力鼓励同事使用它.但是一位(特别是知识渊博的)同事很有耐心,并说老方法更有效率:
private void someMethod(SomeType pointer, SomeType anotherPointer) {
if (pointer == null) {
throw new NullPointerException("pointer cannot be null!");
}
if (anotherPointer == null) {
throw new NullPointerException("anotherPointer cannot be null!");
}
// Rest of method
}
Run Code Online (Sandbox Code Playgroud)
他说调用requireNonNull
涉及在JVM调用堆栈上放置另一个方法,并且会导致比简单== null
检查更差的性能.
所以我的问题是:有没有证据表明使用这些Objects.requireNonNull
方法会导致性能损失?
我正在尝试使用Matlab小波工具箱中提供的函数来创建图像的多级离散小波分解,提取系数,操纵它们,并将它们重新组合回图像.
我尝试使用了许多功能,但它们似乎都不能满足我的需要.这些是执行此操作的步骤.
使用wavedec2将图像分解为[C,S].
[C,S] = wavedec2(X,N,Lo_D,Hi_D)
然后我必须使用detcoef2从[C,S]中提取细节系数.[C,S]是'小波分解结构',它不代表实际系数,如cD,cH,cV.
[H,V,D] = detcoef2('all',C,S,N)
操纵数据
重建[C,S] ???? 没有功能这样做.
使用waverec2重新构图原始图像.
X = waverec2(C,S,Lo_R,Hi_R)
问题出在第4步.没有重新创建[C,S]的函数,我无法调用函数waverec2,因为它需要C和S的操作版本.
我不需要wavedec2和waverec2吗?也许我应该使用detcoef2和upcoef2?
有一些DWT经验的人可以在一分钟内解决这个问题,我对它很新.
谢谢
任何人都可以帮我用Matlab创建一个长度为1000的简单伪随机序列+ -1整数?
即一个序列,如
-1 -1 1 1 -1 -1 1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 1
Run Code Online (Sandbox Code Playgroud)
我尝试使用下面的代码,但这是RANGE -1到1,其中包含0个值.我只想要-1和1.谢谢
x = randi([-1 1],1000,1);
Run Code Online (Sandbox Code Playgroud)