我有一个对象数组,我流式传输以在每个对象上使用一个函数来修改它并将其添加到一个全新的对象数组中。
通过使用,.parallel()执行时间加快了 2 倍,但是NullPointerException在循环新数组时我得到了一些 s 。
我尝试调试了几次,但没有成功。看来这个问题只发生在运行时。我尝试实现一个同步函数来将新对象添加到列表中,但遗憾的是它效果不佳。
谁能给我一个建议如何让它发挥作用?提前致谢!
这是代码片段:
private static final Object sync = new Object();
private ArrayList<Object> newList = new ArrayList<Object>();
private void addNewObject(Object newObject) {
synchronized (sync) {
newList.add(newObject);
}
}
private Object mutateObject(Object oldObject) {
// Do something with the object here
return mutatedObject;
}
public ArrayList<Object> createNewList(ArrayList<Object> oldList) {
oldList.stream().parallel().forEach(object -> addNewObject(mutateObject(object)));
return newList;
}
Run Code Online (Sandbox Code Playgroud) 所以我想在我的页面的vue-component中使用vue-html-editor但它不起作用.我是vue和vue组件的新手,所以我认为这应该是一项简单的任务,但不知怎的,我很蠢到要把它弄好.
我的组件:
<template>
<div class="container">
<vue-html-editor name="html-editor" :model.sync="text"></vue-html-editor>
<div style="margin-top:40px">
<div> The HTML contents are as follows:</div>
<hr>
<div>{{ text }}</div>
</div>
</div>
</template>
<script>
export default {
name: 'Edit',
components: {
"vue-html-editor": require("vue-html-editor")
},
data() {
return {
text: 'Start writing your notes here...'
}
}
}
</script>
<style scoped>
</style>
Run Code Online (Sandbox Code Playgroud)
和控制台错误消息:
vue.esm.js?efeb:591 [Vue warn]: Failed to mount component: template or render function not defined.
found in
---> <VueHtmlEditor>
<Edit> at src/components/Edit.vue
<App> at src/App.vue
<Root>
Run Code Online (Sandbox Code Playgroud)
我已经安装了vue-html-editor但我认为我没有正确加载编辑器. …