- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试提交这个声音处理程序,但我不断收到此错误:
Assignment requires a deep, not shallow copy. Are you just copying pointers, or copying the contents of the array?...
我想我正在对我的 public void set(double[] mySamples
) 进行浅拷贝,但我是 Java 新手,真的不知道该怎么做。
public class Sound
{
private double[] temp;
private double[] samples;
public Sound() {
samples = null;
}
public Sound(Sound s) {
int j = 0;
double[] source = s.samples;
double temp[] = new double[source.length];
for(int i = 0; i < source.length; i++) {
temp[j] = source[i];
}
samples = temp;
}
public double[] get() {
return samples;
}
public void set(double[] mySamples) {
if (mySamples == null) {
throw new IllegalArgumentException("samples cannot be null");
} else {
samples = mySamples;
}
}
public void increaseVol(double percent) {
double [] result = new double[samples.length];
for (int i = 0; i < samples.length; i++) {
double reduce = samples[i] * percent;
result[i] = samples[i] + reduce;
}
samples = result;
}
public void wavSave(java.lang.String fileName) {
WavIO.write(fileName, samples);
}
}
最佳答案
我认为你需要做两处改变 -
1 你的构造函数正在对这些样本做一些奇怪的事情(并且可能会导致你的错误本身) - 我不确定你想要做什么,但我认为你应该推迟设置。
public Sound(Sound s) {
int j = 0;
set(s.samples);
}
2 只需复制 set 中的样本数组并存储即可。
public void set(double[] mySamples) {
if (mySamples == null) {
throw new IllegalArgumentException(
"samples cannot be null");
} else {
samples = new double[mySamples.length];
for (int i = 0; i < mySamples.length; i++) {
samples[i] = mySamples[i];
}
}
}
关于java - 为什么我的 Java 深度复制代码告诉我 "Assignment requires a deep, not shallow copy"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20110811/
我正在上一门关于使用 C++ 进行面向对象编程的类(class)。 在我们的文字中说, If we do not declare a copy constructor, the compiler in
我正在尝试从本地裸克隆创建一个 --shallow-since 工作克隆,但它一直在 pull 所有内容。 --depth=N 工作正常。 我在想问题是我使用了错误的格式吗?我试过搜索,但没有明确说明
浅谈克隆扩展 有一些关于 Mercurial 的非官方浅克隆扩展的工作的讨论。这个扩展的功能类似于 git clone --depth X扩展,但会提供更好的推送支持和合并安全。 基本上,它会让用户克
我可以在 git clone 的 --shallow-since= 中使用相对相对日期(例如,像one-year-ago这样的东西)吗? 命令替换(例如$(one-year-ago-command)中
我有这个组件,它在应用程序中运行良好: class TheComponent extends Component { componentDidMount() { this.watchFor
假设我有这样一个组件: class ExampleComponent extends Component { exampleMethod = () => { this.props.exam
__clone() 的结果是“浅克隆”是什么意思? 最佳答案 这意味着当对象被克隆时,任何作为引用变量的属性(引用其他对象的变量,而不是值)将保持引用。 “非浅层”克隆会将新对象设置为这些属性的值,而
我在调试 C++ 类时遇到了麻烦。这是一张图表,像这样: class Graph { class Node { std::map::iterator _neighbors[4]
我正在尝试缩小一个大存储库以减少服务器负载。我正在使用命令 git clone --depth 1000 url 但是当克隆完成后我只有一个分支。未克隆的分支是新的(3 周左右),克隆的历史有 3 个
发出命令 git clone --bare/path/to/repo 时出现以下错误: 致命:尝试从浅存储库中获取/克隆 首先,什么是浅存储库,为什么它不允许我克隆它? 最佳答案 将 .git/sha
我想使用浅层渲染来测试 React 组件。但我想根据组件的状态来测试它。 这样做的正确方法是什么?我已经尝试过: component = shallowRenderer.render(
我正在尝试开始 Jest 并进行快照测试。我过去实际上已经完成了这个工作,我看到了下面的错误,所以我继续阅读并尽可能升级软件包,但我仍然收到错误。 Splash.test.js import { sh
开个 Jest ,使用 shallow 和 render from enzyme 有什么区别? 下面是两者的例子: 用浅层测试渲染: import "jest"; import * as React
我在测试我的组件时遇到问题,该组件薄薄地包装了 Material-UI 自动完成功能。在我的测试中,我想查看传递给的 Prop ,但我的控制台语句是一个空对象。我正在使用 Enzyme 的浅层方法来渲
当使用 Jackson 序列化对象列表时,我想控制对象是“深”还是“浅”序列化。 例如:测试有两个 X 类对象列表 public class Test { public List list1;
这个问题在这里已经有了答案: What is the difference between shallow copy, deepcopy and normal assignment operatio
想知道为什么我的/articles 路由在我申请时没有出现 :shallow => true? 路线.rb resources :users, :shallow => true do resour
我有一个大小约为 24MB 的存储库,但项目中的文件实际上只有 2MB 左右。我的印象是,带有 --depth 1 的浅克隆几乎会让我接近 2MB 的实际文件(没有整个 repo)。 当我进行浅克隆时
克隆远程仓库后,它不会通过 -a 选项显示任何远程分支。可能是什么问题呢?如何调试呢?在此片段中,未显示两个远程分支: $ git clone --depth 1 git://git.savannah
我看过这个答案for a git clone error ,建议不要克隆整个 repo,而是只克隆最新的提交,然后使用 unshallow 获取其余的提交。 考虑以下两个命令 1. git clone
我是一名优秀的程序员,十分优秀!